Commit d5aeccf
committed
asyncio, Tulip issue 205: Fix a race condition in BaseSelectorEventLoop.sock_connect()
There is a race condition in create_connection() used with wait_for() to have a
timeout. sock_connect() registers the file descriptor of the socket to be
notified of write event (if connect() raises BlockingIOError). When
create_connection() is cancelled with a TimeoutError, sock_connect() coroutine
gets the exception, but it doesn't unregister the file descriptor for write
event. create_connection() gets the TimeoutError and closes the socket.
If you call again create_connection(), the new socket will likely gets the same
file descriptor, which is still registered in the selector. When sock_connect()
calls add_writer(), it tries to modify the entry instead of creating a new one.
This issue was originally reported in the Trollius project, but the bug comes
from Tulip in fact (Trollius is based on Tulip):
https://bitbucket.org/enovance/trollius/issue/15/after-timeouterror-on-wait_for
This change fixes the race condition. It also makes sock_connect() more
reliable (and portable) is sock.connect() raises an InterruptedError.1 parent 41f3c3f commit d5aeccf
File tree
2 files changed
+83
-35
lines changed- Lib
- asyncio
- test/test_asyncio
2 files changed
+83
-35
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
345 | 346 | | |
346 | 347 | | |
347 | 348 | | |
348 | | - | |
| 349 | + | |
349 | 350 | | |
350 | 351 | | |
351 | | - | |
| 352 | + | |
352 | 353 | | |
353 | | - | |
354 | | - | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
355 | 375 | | |
356 | 376 | | |
| 377 | + | |
357 | 378 | | |
358 | | - | |
359 | | - | |
360 | | - | |
361 | | - | |
362 | | - | |
363 | | - | |
364 | | - | |
365 | | - | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
366 | 383 | | |
367 | | - | |
| 384 | + | |
| 385 | + | |
368 | 386 | | |
369 | 387 | | |
370 | 388 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
44 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
| |||
303 | 304 | | |
304 | 305 | | |
305 | 306 | | |
306 | | - | |
| 307 | + | |
307 | 308 | | |
308 | 309 | | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
309 | 333 | | |
310 | 334 | | |
311 | 335 | | |
312 | 336 | | |
313 | 337 | | |
314 | 338 | | |
315 | | - | |
| 339 | + | |
316 | 340 | | |
317 | 341 | | |
318 | 342 | | |
319 | 343 | | |
320 | | - | |
| 344 | + | |
321 | 345 | | |
| 346 | + | |
322 | 347 | | |
323 | 348 | | |
324 | 349 | | |
325 | 350 | | |
326 | | - | |
327 | | - | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
328 | 359 | | |
329 | | - | |
330 | 360 | | |
331 | 361 | | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
332 | 365 | | |
333 | 366 | | |
334 | | - | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
335 | 370 | | |
336 | | - | |
337 | | - | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
338 | 374 | | |
339 | 375 | | |
340 | | - | |
| 376 | + | |
341 | 377 | | |
342 | 378 | | |
343 | 379 | | |
344 | 380 | | |
345 | 381 | | |
346 | | - | |
347 | | - | |
348 | | - | |
349 | | - | |
350 | | - | |
351 | | - | |
352 | | - | |
353 | | - | |
| 382 | + | |
| 383 | + | |
354 | 384 | | |
355 | | - | |
| 385 | + | |
356 | 386 | | |
357 | 387 | | |
358 | 388 | | |
359 | 389 | | |
360 | 390 | | |
361 | 391 | | |
362 | | - | |
| 392 | + | |
363 | 393 | | |
364 | 394 | | |
365 | 395 | | |
| |||
0 commit comments