mirror of
https://github.com/python/cpython.git
synced 2025-07-23 11:15:24 +00:00
There was a race condition where the connector would try to connect
before the listener was ready (on gentoo x86 buildslave). This caused the listener to not exit normally since nobody connected to it (waited in accept()). The exception was raised in the other thread and the test failed. This fix doesn't completely eliminate the race, but should make it near impossible to trigger. Hopefully it's good enough.
This commit is contained in:
parent
14361fffc2
commit
08e301f8bd
1 changed files with 3 additions and 0 deletions
|
@ -35,6 +35,7 @@ def test_rude_shutdown():
|
||||||
# Some random port to connect to.
|
# Some random port to connect to.
|
||||||
PORT = 9934
|
PORT = 9934
|
||||||
|
|
||||||
|
listener_ready = threading.Event()
|
||||||
listener_gone = threading.Event()
|
listener_gone = threading.Event()
|
||||||
|
|
||||||
# `listener` runs in a thread. It opens a socket listening on PORT, and
|
# `listener` runs in a thread. It opens a socket listening on PORT, and
|
||||||
|
@ -45,11 +46,13 @@ def test_rude_shutdown():
|
||||||
s = socket.socket()
|
s = socket.socket()
|
||||||
s.bind(('', PORT))
|
s.bind(('', PORT))
|
||||||
s.listen(5)
|
s.listen(5)
|
||||||
|
listener_ready.set()
|
||||||
s.accept()
|
s.accept()
|
||||||
s = None # reclaim the socket object, which also closes it
|
s = None # reclaim the socket object, which also closes it
|
||||||
listener_gone.set()
|
listener_gone.set()
|
||||||
|
|
||||||
def connector():
|
def connector():
|
||||||
|
listener_ready.wait()
|
||||||
s = socket.socket()
|
s = socket.socket()
|
||||||
s.connect(('localhost', PORT))
|
s.connect(('localhost', PORT))
|
||||||
listener_gone.wait()
|
listener_gone.wait()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue