Commit ac93972
committed
fix race crash for accepting new connections
Inspired by a patch by Kazuki Ohta.
Summary from a mail sent to the list by Shigeki:
[Example Scenario]
1. throw alot clients (well over connection limit) to connect to
memcached.
2. memcached's file descriptors reaches maximum setting
3. main thread calls accept_new_conns(false) to stop polling sfd
4. main thread's event_base_loop stops accepting incoming request
5. main thread stops to acceess main_base at this point
6. a client disconnects
7. worker thread calls accept_new_conns(true) to start polling sfd
8. accept_new_conns uses mutex to protect main_base's race condition
9. worker thread starts loop with listen_conn
10. worker thread calls update_event with first conn
11. after first update_event(), main thread start polling sfd and
starts to access main_base <- PROBLEM
12. Worker thread continues to call update_event() with second conn
At this point, worker thread and main thread both acccess and modify
main_base.
---
The original patch coupled polling with the once-per-second clock timer. My
patch creates a 10ms poller which kicks off after the listener is disabled.
Switching for a conditional would be too much rewiring for 1.4, as 1.6 solves
this in a better way.1 parent 0d45e55 commit ac93972
1 file changed
+26
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
120 | 120 | | |
121 | 121 | | |
122 | 122 | | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
123 | 144 | | |
124 | 145 | | |
125 | 146 | | |
| |||
509 | 530 | | |
510 | 531 | | |
511 | 532 | | |
512 | | - | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
513 | 536 | | |
514 | 537 | | |
515 | 538 | | |
| |||
3363 | 3386 | | |
3364 | 3387 | | |
3365 | 3388 | | |
| 3389 | + | |
| 3390 | + | |
3366 | 3391 | | |
3367 | 3392 | | |
3368 | 3393 | | |
| |||
0 commit comments