Summary: | Avoid a race condition in close_worker_sockets() | ||
---|---|---|---|
Product: | Apache httpd-2 | Reporter: | Bojan Smojver <bojan> |
Component: | mpm_worker | Assignee: | Apache HTTPD Bugs Mailing List <bugs> |
Status: | NEW --- | ||
Severity: | normal | CC: | arekm |
Priority: | P2 | ||
Version: | 2.5-HEAD | ||
Target Milestone: | --- | ||
Hardware: | PC | ||
OS: | Linux | ||
Attachments: |
(Hopefully) safe close_worker_sockets()
Same for 2.2.x (Hopefully) safe close_worker_sockets() Same for 2.2.x (Hopefully) safe close_worker_sockets() Same for 2.2.x |
Created attachment 24450 [details]
Same for 2.2.x
Please note, I actually tested the 2.2.x patch. The patch against trunk has been edited to apply. Created attachment 24453 [details]
(Hopefully) safe close_worker_sockets()
Somewhat simpler and more Unixy patch, using sigsuspend() and atomic counters.
Created attachment 24454 [details]
Same for 2.2.x
Created attachment 24510 [details]
(Hopefully) safe close_worker_sockets()
Simpler and safer patch. Instead of suspending workers (which may hang the server in some corner cases), we simply send signals to worker threads. Once the signal handler is executed for a worker thread, we are guaranteed that the other worker code isn't going to be executing, so we avoid the race.
Created attachment 24511 [details]
Same for 2.2.x
|
Created attachment 24449 [details] (Hopefully) safe close_worker_sockets() Current code closes worker sockets in close_worker_sockets() from the listener thread without suspending the workers. At the same time, worker threads may be in the process of doing the same (they may even set worker_sockets[i] to NULL, causing a segfault in the listener), potentially causing problems. The attached patch suspends worker threads first and then shuts down sockets, using shutdown(). This way, worker threads can still proceed later with regular close, without any side effects.