Bug 48094 - Avoid a race condition in close_worker_sockets()
Summary: Avoid a race condition in close_worker_sockets()
Status: NEW
Alias: None
Product: Apache httpd-2
Classification: Unclassified
Component: mpm_worker (show other bugs)
Version: 2.5-HEAD
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: ---
Assignee: Apache HTTPD Bugs Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-11-01 00:42 UTC by Bojan Smojver
Modified: 2009-11-10 02:12 UTC (History)
1 user (show)



Attachments
(Hopefully) safe close_worker_sockets() (4.41 KB, patch)
2009-11-01 00:42 UTC, Bojan Smojver
Details | Diff
Same for 2.2.x (4.43 KB, patch)
2009-11-01 00:42 UTC, Bojan Smojver
Details | Diff
(Hopefully) safe close_worker_sockets() (3.43 KB, patch)
2009-11-01 14:47 UTC, Bojan Smojver
Details | Diff
Same for 2.2.x (3.33 KB, patch)
2009-11-01 14:48 UTC, Bojan Smojver
Details | Diff
(Hopefully) safe close_worker_sockets() (2.32 KB, patch)
2009-11-10 02:11 UTC, Bojan Smojver
Details | Diff
Same for 2.2.x (2.22 KB, patch)
2009-11-10 02:12 UTC, Bojan Smojver
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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