Re:How we reduced deployment times by 95%
by otterley on Wednesday August 28, 2019 @02:40PM
(#20822684)
I've built services that can gracefully shut down, and my typical design is as follows:
First, maintain an active request counter that you increment when you accept a request and decrement when the request has been fully delivered (including output buffer drained).
Second, implement a TERM signal handler. The handler shuts down the listening socket (so no new connections will be accepted), starts a countdown timer, and waits for the active-request counter to reach 0. When either the countdown timer expires or the active-request counter reaches 0, exit.
First, maintain an active request counter that you increment when you accept a request and decrement when the request has been fully delivered (including output buffer drained).
Second, implement a TERM signal handler. The handler shuts down the listening socket (so no new connections will be accepted), starts a countdown timer, and waits for the active-request counter to reach 0. When either the countdown timer expires or the active-request counter reaches 0, exit.