Bug 46963

Summary: KeepAliveTimout prevents child process from exiting cleanly with winnt_mpm
Product: Apache httpd-2 Reporter: NG <neel.goyal>
Component: mpm_winntAssignee: Apache HTTPD Bugs Mailing List <bugs>
Status: RESOLVED LATER    
Severity: normal CC: steven.BUSH
Priority: P2 Keywords: MassUpdate
Version: 2.2.11   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   

Description NG 2009-04-03 10:16:56 UTC
Version 2.2.11

My assumption is if a persistent connection is made to the server with KeepAlive On, the request thread will not terminate until the KeepAlive timeout or the connection is closed by the client.

in server/mpm/winnt/child.c the child waits for the threads to exit.  Around line 1119.  It waits X seconds where X is the time specified in the Timeout directive.  The thread is forcibly closed after X seconds (line 1180) and then destroy the child pool properly (line 1208).

However, in server/mpm/winnt/mpm_winnt.c the parent process decides it's time to kill the child after a hardcoded 30 seconds (line 964).  This ends up killing the child process without destroying the child pool.  Thus, registered callbacks fail to properly cleanup.

This may also be linked to Bug 41743 which also describes shutdown errors with KeepAlive On
Comment 1 Steven Bush 2012-12-20 23:22:43 UTC
I just ran into this as well.  We have a custom module that has a hook into the shutdown via apr_pool_cleanup_register().

If the KeepAliveTimeout is set to anything greater than 30 seconds (the hardcoded "death to all children time" as mentioned in NG's comment), our cleanup is never called and various resources fail to get cleaned up.

We're working around this through other means, but it seems that when the server is shutting down, the child thread that is in a keep-alive state waiting for a further request should close its socket and exit rather than waiting for the end of the keep-alive timeout.  For one thing, any further requests by the client will be ignored, so there doesn't appear to be a benefit to staying open.

You can see the effect quite easily with a simple configuration:

1. httpd.conf with KeepAliveTimeout set to something > 30 seconds (say 60)
2. a Module with a cleanup hooked into apr_pool_cleanup_register()
3. start server
4. make a single keep-alive request to server-status (or any other resource)
5. shut down server
-->  you will find that the server takes ~30 seconds to shutdown and the cleanup is never called

Repeat, but eliminate the connection in step 4:
--> process shuts down in ~2-5 seconds and clean up is called

Repeat, but this time reduce the KeepAliveTimeout to < 10 seconds (say 10)
--> process shuts down in ~5-15 seconds and clean up is called
Comment 2 William A. Rowe Jr. 2018-11-07 21:09:26 UTC
Please help us to refine our list of open and current defects; this is a mass update of old and inactive Bugzilla reports which reflect user error, already resolved defects, and still-existing defects in httpd.

As repeatedly announced, the Apache HTTP Server Project has discontinued all development and patch review of the 2.2.x series of releases. The final release 2.2.34 was published in July 2017, and no further evaluation of bug reports or security risks will be considered or published for 2.2.x releases. All reports older than 2.4.x have been updated to status RESOLVED/LATER; no further action is expected unless the report still applies to a current version of httpd.

If your report represented a question or confusion about how to use an httpd feature, an unexpected server behavior, problems building or installing httpd, or working with an external component (a third party module, browser etc.) we ask you to start by bringing your question to the User Support and Discussion mailing list, see [https://httpd.apache.org/lists.html#http-users] for details. Include a link to this Bugzilla report for completeness with your question.

If your report was clearly a defect in httpd or a feature request, we ask that you retest using a modern httpd release (2.4.33 or later) released in the past year. If it can be reproduced, please reopen this bug and change the Version field above to the httpd version you have reconfirmed with.

Your help in identifying defects or enhancements still applicable to the current httpd server software release is greatly appreciated.