Staging
v0.5.1
https://github.com/python/cpython
Revision d5aeccf9767c1619faa29e8ed61c93bde7bc5e3f authored by Victor Stinner on 31 August 2014, 13:07:57 UTC, committed by Victor Stinner on 31 August 2014, 13:07:57 UTC
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
History
Tip revision: d5aeccf9767c1619faa29e8ed61c93bde7bc5e3f authored by Victor Stinner on 31 August 2014, 13:07:57 UTC
asyncio, Tulip issue 205: Fix a race condition in BaseSelectorEventLoop.sock_connect()
Tip revision: d5aeccf
File Mode Size
Python.asdl -rw-r--r-- 4.4 KB
acceler.c -rw-r--r-- 3.3 KB
asdl.py -rw-r--r-- 11.5 KB
asdl_c.py -rwxr-xr-x 42.7 KB
bitset.c -rw-r--r-- 1.0 KB
firstsets.c -rw-r--r-- 2.8 KB
grammar.c -rw-r--r-- 6.8 KB
grammar1.c -rw-r--r-- 1.3 KB
listnode.c -rw-r--r-- 1.2 KB
metagrammar.c -rw-r--r-- 2.4 KB
myreadline.c -rw-r--r-- 6.1 KB
node.c -rw-r--r-- 4.4 KB
parser.c -rw-r--r-- 11.6 KB
parser.h -rw-r--r-- 1.0 KB
parsetok.c -rw-r--r-- 10.5 KB
parsetok_pgen.c -rw-r--r-- 35 bytes
pgen.c -rw-r--r-- 17.5 KB
pgenmain.c -rw-r--r-- 3.8 KB
printgrammar.c -rw-r--r-- 2.9 KB
spark.py -rw-r--r-- 26.5 KB
tokenizer.c -rw-r--r-- 49.7 KB
tokenizer.h -rw-r--r-- 3.4 KB
tokenizer_pgen.c -rw-r--r-- 36 bytes

back to top