Title: test_socket.NonBlockingTCPTests failing due to race condition
Type: behavior Stage: resolved
Components: Tests Versions: Python 3.5
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: pitrou, steve.dower, vstinner
Priority: normal Keywords:

Created on 2015-03-15 04:23 by steve.dower, last changed 2017-09-11 21:52 by vstinner. This issue is now closed.

Messages (2)
msg238121 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2015-03-15 04:23
The test at Lib/test/ is failing intermittently (but more often than not) due to a race condition between the two threads involved in the test.

FAIL: testRecv (test.test_socket.NonBlockingTCPTests)
Traceback (most recent call last):
  File "C:\build\cpython\lib\test\", line 3883, in testRecv"Error trying to do non-blocking recv.")
AssertionError: Error trying to do non-blocking recv.


The message in this case means the recv succeeded when it should have failed due to lack of data. But the second thread just delays briefly before sending data, and apparently the main thread can stall long enough for the data to be available in the first part of the test.

A quick check using an Event rather than the sleep shows that the race condition can be fixed, but it seems like this may affect more tests as a lot seem to involve sleep-based timing.

(I've only seen this on Windows, but I see no reason why it shouldn't affect other platforms as well.)
msg301912 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-09-11 21:52
I didn't see this message last 6 months even if we now have a long list of Windows buildbots. So I consider that the bug was fixed in the meanwhile.
Date User Action Args
2017-09-11 21:52:37vstinnersetstatus: open -> closed

nosy: + vstinner
messages: + msg301912

resolution: fixed
stage: resolved
2015-03-15 04:23:48steve.dowercreate