On Jan 2, 2007, at 22:25, Kevin Scaldeferri wrote:

I've been digging through the website and mailing list archives, and I'm still puzzled about how to achieve a graceful server shutdown.

By this, I mean something similar to 'apachectl graceful', where new requests are refused, but any existing requests are fully processed before the server performs shutdown functions and terminates.

My server is an HTTP server using PoCo::Server::TCP, which runs a fairly simple state machine to gather up all the information required for each request and then puts it together to construct the reply. It seems to me like implementing the graceful shutdown requires 3 parts:

1) a signal handler that sets a global "shutting down" flag

Good. It should also send a "shutdown" signal to the POE::Component::Server::TCP instance's alias. This shuts down the listener but leaves the children running.

2) in my ClientInput callback, to only start the state machine if the flag is not set

Not necessary.  New clients will not be accepted.

3) somehow determine that all current requests have finished, and shutdown if the flag is set. This is the part that I'm stuck on.

Not necessary. If your server is doing nothing else, it will exit after the last client disconnects. If you need to trigger a more complex shutdown after the last client disconnects, then you will need a shutdown flag and an active connection counter:

a. Send the Server::TCP instance a "shutdown" message.
b. Set the global shutdown flag.
c. If the active session count is 0, commence complex shutdown.
d. Otherwise, increment the active session count from the ClientConnected callback, and decrement it from the ClientDisconnected callback. e. When the active session count reaches 0, and the shutdown flag is set, begin complex shutdown.

--
Rocco Caputo - [EMAIL PROTECTED]


Reply via email to