Exercise 3: Why Requests Were Cut Off, and How preStop Fixes It — Possible Solution ==================================================================== WHY IN-FLIGHT REQUESTS WERE BEING CUT OFF ------------------------------ Per this chapter's worked example, "old instances are terminated the instant the new version becomes ready, with no drain period configured at all. Requests still in flight on an old instance at that exact moment get abruptly cut off mid-response." The old instance was killed immediately, with no step in between to stop new traffic and let existing requests finish - any request that happened to still be processing at that exact instant was interrupted mid-execution, with no chance to complete and send its response. WHY THIS IS A LIFECYCLE PROBLEM, NOT A CODE BUG ------------------------------ Nothing about the application's own logic was wrong - the requests themselves would have completed successfully if simply given the chance. The problem was purely about timing and sequencing during shutdown: the process was terminated before it had finished the work it was already doing. HOW A preStop HOOK FIXES IT ------------------------------ Per this chapter, the fix was "adding a preStop hook that pauses before actual termination - giving the load balancer time to stop routing new traffic and letting existing requests finish." A preStop hook runs before the container is actually killed, providing exactly the missing drain window: the instance can be marked not-ready (so no new requests arrive) and given time to finish whatever it was already processing, before termination actually happens. WHY THIS DOESN'T CHANGE THE DEPLOYMENT'S OWN LOGIC ------------------------------ Per this chapter, the fix resolves the blip "without changing anything about the deployment's own speed or correctness." The preStop hook only affects the shutdown sequencing of the old instance being replaced - it doesn't alter what the new version does, how fast the rollout proceeds, or any application code at all. WHY THIS WORKS AS AN ANSWER ------------------------------ It explains the precise mechanism by which requests were interrupted (immediate termination, no drain), and explains specifically how a preStop hook inserts the missing delay without touching application logic or deployment speed.