[Python-checkins] r42185 - python/trunk/Lib/test/test_socket_ssl.py
Tim Peters
tim.peters at gmail.com
Thu Jan 26 02:35:17 CET 2006
[neal.norwitz]
> Modified:
> python/trunk/Lib/test/test_socket_ssl.py
> Log:
> 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.
Good catch! Thank you.
> This fix doesn't completely eliminate the race, but should make it
> near impossible to trigger. Hopefully it's good enough.
Which race do you have in mind? The server socket doesn't need to do
.accept() before a client socket can connect -- the server socket only
needs to have done .listen() for a connection to succeed.
> + listener_ready = threading.Event()
...
[in the server]
> s = socket.socket()
> s.bind(('', PORT))
> s.listen(5)
> + listener_ready.set()
> s.accept()
...
[in the client]
> def connector():
> + listener_ready.wait()
> s = socket.socket()
> s.connect(('localhost', PORT))
Because the server doesn't set listener_ready until after the server
has done listen(), and the client waits for that event, it "should
be" 100% reliable that the client's connect() succeeds.
Or do you have some other race in mind?
More information about the Python-checkins
mailing list