Closed lesteve closed 1 year ago
Hi @lesteve, thanks for the bug report. This looks like it's due to the order of destruction of local variables: upstream CPython clears the variables in order they were created (listener, client, server), while "nogil" Python clears them in reverse order (server, client, listener.) The order of destruction affects which ends closes the socket first, which affects which socket ends up in the TIME_WAIT state. If it's the socket with a randomly assigned port (the "accepted" socket), it's not an issue. If it's port 12345, you get an address already in use error when re-running the example.
The difference in behavior here was not intentional, but at this point I'm hesitant to change it and risk introducing other bugs. I don't expect this behavioral change to be part of PEP 703.
That might be the similar PySide bug
@ctismer They are similar in that they both have to do with order of destruction, but they involve separate code paths.
Thanks a lot @colesbury for your answer, our code was a bit edge-casy. The behaviour change is slightly surprising but the work-around is easy so I am fine closing this issue.
Maybe the following code is a bit edge-casy and is not supposed to work. The behaviour is different from CPython so I thought I would report it. I noticed this while trying to run the joblib tests with nogil, see https://github.com/joblib/joblib/pull/1387 for more details.
Running the script the first time works fine:
The second time I get a
OSError: [Errno 98] Address already in use
:Output:
A possible work-around is to explicitly close the client e.g. like this:
Not a networking expert, but here is the
netstat
output after running the script the first time: