HyperFastCgi icon indicating copy to clipboard operation
HyperFastCgi copied to clipboard

Shutting down gracefully after all current requests have been closed

Open derFunk opened this issue 7 years ago • 2 comments

As far as I can see it seems that there is no real graceful shutdown implemented for the Listeners. After sending a SIGTERM/SIGINT, HFC is not waiting for all current web requests to be processed, right?

This results in several exceptions when stopping HFC, e.g. ThreadAbortExceptions, e.g. when ServiceStack is being used.

Would it be possible to implement this in general?:

  • After receiving a SIGTERM/SIGINT, don't accept new incoming connections but answer with a dedicated http error code
  • After receiving a SIGTERM/SIGINT, still process the currently active requests
  • After all requests have been processed, finally shutdown the listener and exit the process.

derFunk avatar Aug 30 '16 12:08 derFunk

HyperFastCGI do it exactly the same way like ASP.NET does - aborts currently running threads and shuts down the application. If it will wait till all requests are served it will never be stopped in case of long-polling HTTP requests. Moreover some of thread aborts (for example reloading app domain when changing web.config) cannot be controlled by HyperFastCGI because are managed directly by mono implementation of System.Web and HyperFastCGI just be notified from System.Web that domain is unloading. However it's possible to make improvement to stop receive incoming connections and wait some small amount of time after SIGTERM to process working requests.

xplicit avatar Aug 30 '16 12:08 xplicit

Ok, thanks. Regarding long polling requests - it should be able to recognize these connections, right? these could/should be simply closed then, whereas non-long-polling ones should wait until they have been processed (which can take a while, e.g. 60s, I agree).

Maybe introducing the "graceful connection shutdown" behaviour could be introduced by an optional command line argument.

derFunk avatar Aug 31 '16 16:08 derFunk