Bug 48094

Summary: Avoid a race condition in close_worker_sockets()
Product: Apache httpd-2 Reporter: Bojan Smojver <bojan>
Component: mpm_workerAssignee: 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

Description Bojan Smojver 2009-11-01 00:42:20 UTC
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.
Comment 1 Bojan Smojver 2009-11-01 00:42:43 UTC
Created attachment 24450 [details]
Same for 2.2.x
Comment 2 Bojan Smojver 2009-11-01 00:44:29 UTC
Please note, I actually tested the 2.2.x patch. The patch against trunk has been edited to apply.
Comment 3 Bojan Smojver 2009-11-01 14:47:34 UTC
Created attachment 24453 [details]
(Hopefully) safe close_worker_sockets()

Somewhat simpler and more Unixy patch, using sigsuspend() and atomic counters.
Comment 4 Bojan Smojver 2009-11-01 14:48:00 UTC
Created attachment 24454 [details]
Same for 2.2.x
Comment 5 Bojan Smojver 2009-11-10 02:11:46 UTC
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.
Comment 6 Bojan Smojver 2009-11-10 02:12:13 UTC
Created attachment 24511 [details]
Same for 2.2.x