A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2006-January/060082.html below:

[Python-Dev] [Python-checkins] r42185 - python/trunk/Lib/test/test_socket_ssl.py

[Python-Dev] [Python-checkins] r42185 - python/trunk/Lib/test/test_socket_ssl.py [Python-Dev] [Python-checkins] r42185 - python/trunk/Lib/test/test_socket_ssl.pyTim 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-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4