[Python-Dev] [Python-checkins] r42185 - python/trunk/Lib/test/test_socket_ssl.py (original) (raw)
Tim Peters tim.peters at gmail.com
Thu Jan 26 02:35:17 CET 2006
- Previous message: [Python-Dev] The path module PEP
- Next message: [Python-Dev] [Python-checkins] r42185 - python/trunk/Lib/test/test_socket_ssl.py
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
[neal.norwitz]
Modified: python/trunk/Lib/test/testsocketssl.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.
+ listenerready = threading.Event()
...
[in the server]
s = socket.socket() s.bind(('', PORT)) s.listen(5) + listenerready.set() s.accept()
...
[in the client]
def connector(): + listenerready.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?
- Previous message: [Python-Dev] The path module PEP
- Next message: [Python-Dev] [Python-checkins] r42185 - python/trunk/Lib/test/test_socket_ssl.py
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]