Repository navigation
test_threading fails and crashes when rerun #108987
Copy link
Copy link
Closed
Labels
OS-windowstype-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump
Description
Crash report
First, BarrierTests.test_default_timeout in test_threading fails, producing also several unraisable exception messages. They are produced even during running few following tests.
https://github.com/python/cpython/actions/runs/6094370280/job/16535778004#step:5:103
test_default_timeout (test.test_threading.BarrierTests.test_default_timeout)
Test the barrier's default timeout ... Warning -- Unraisable exception
Exception ignored in thread started by: <function Bunch.__init__.<locals>.task at 0x053F5270>
Traceback (most recent call last):
File "D:\a\cpython\cpython\Lib\test\lock_tests.py", line 48, in task
f()
File "D:\a\cpython\cpython\Lib\test\lock_tests.py", line 1020, in f
i = barrier.wait()
^^^^^^^^^^^^^^
File "D:\a\cpython\cpython\Lib\threading.py", line 709, in wait
self._wait(timeout)
File "D:\a\cpython\cpython\Lib\threading.py", line 749, in _wait
raise BrokenBarrierError
threading.BrokenBarrierError:
ERROR
test_repr (test.test_threading.BarrierTests.test_repr) ... Warning -- Unraisable exception
Exception ignored in thread started by: <function Bunch.__init__.<locals>.task at 0x053F5270>
Traceback (most recent call last):
File "D:\a\cpython\cpython\Lib\test\lock_tests.py", line 48, in task
f()
File "D:\a\cpython\cpython\Lib\test\lock_tests.py", line 1020, in f
i = barrier.wait()
^^^^^^^^^^^^^^
File "D:\a\cpython\cpython\Lib\threading.py", line 709, in wait
self._wait(timeout)
File "D:\a\cpython\cpython\Lib\threading.py", line 749, in _wait
raise BrokenBarrierError
threading.BrokenBarrierError:
Warning -- Unraisable exception
Exception ignored in thread started by: <function Bunch.__init__.<locals>.task at 0x053F5270>
Traceback (most recent call last):
File "D:\a\cpython\cpython\Lib\test\lock_tests.py", line 48, in task
f()
File "D:\a\cpython\cpython\Lib\test\lock_tests.py", line 1020, in f
i = barrier.wait()
^^^^^^^^^^^^^^
File "D:\a\cpython\cpython\Lib\threading.py", line 709, in wait
self._wait(timeout)
File "D:\a\cpython\cpython\Lib\threading.py", line 749, in _wait
raise BrokenBarrierError
threading.BrokenBarrierError:
Warning -- Unraisable exception
Exception ignored in thread started by: <function Bunch.__init__.<locals>.task at 0x053F5270>
Traceback (most recent call last):
File "D:\a\cpython\cpython\Lib\test\lock_tests.py", line 48, in task
f()
File "D:\a\cpython\cpython\Lib\test\lock_tests.py", line 1020, in f
i = barrier.wait()
^^^^^^^^^^^^^^
File "D:\a\cpython\cpython\Lib\threading.py", line 700, in wait
self._enter() # Block while the barrier drains.
^^^^^^^^^^^^^
File "D:\a\cpython\cpython\Lib\threading.py", line 724, in _enter
raise BrokenBarrierError
threading.BrokenBarrierError:
ok
After rerunning test_threading it crashes.
https://github.com/python/cpython/actions/runs/6094370280/job/16535778004#step:5:1067
0:17:28 Re-running 2 failed tests in verbose mode in subprocesses
0:17:28 Run tests in parallel using 4 child processes (timeout: 20 min, worker timeout: 25 min)
0:17:30 [1/2/1] test_threading process crashed (Exit code 3)
Re-running test_threading in verbose mode (matching: test_default_timeout)
test_default_timeout (test.test_threading.BarrierTests.test_default_timeout)
Test the barrier's default timeout ... Warning -- Unraisable exception
Exception ignored in thread started by: <function Bunch.__init__.<locals>.task at 0x052196F0>
Traceback (most recent call last):
File "D:\a\cpython\cpython\Lib\test\lock_tests.py", line 48, in task
f()
File "D:\a\cpython\cpython\Lib\test\lock_tests.py", line 1020, in f
i = barrier.wait()
^^^^^^^^^^^^^^
File "D:\a\cpython\cpython\Lib\threading.py", line 709, in wait
self._wait(timeout)
File "D:\a\cpython\cpython\Lib\threading.py", line 749, in _wait
raise BrokenBarrierError
threading.BrokenBarrierError:
ERROR
======================================================================
ERROR: test_default_timeout (test.test_threading.BarrierTests.test_default_timeout)
Test the barrier's default timeout
----------------------------------------------------------------------
Traceback (most recent call last):
File "D:\a\cpython\cpython\Lib\test\lock_tests.py", line 1025, in test_default_timeout
self.run_threads(f)
File "D:\a\cpython\cpython\Lib\test\lock_tests.py", line 854, in run_threads
f()
File "D:\a\cpython\cpython\Lib\test\lock_tests.py", line 1020, in f
i = barrier.wait()
^^^^^^^^^^^^^^
File "D:\a\cpython\cpython\Lib\threading.py", line 709, in wait
self._wait(timeout)
File "D:\a\cpython\cpython\Lib\threading.py", line 747, in _wait
raise BrokenBarrierError
threading.BrokenBarrierError
----------------------------------------------------------------------
Ran 1 test in 0.376s
FAILED (errors=1)
test test_threading failed
{"test_name": "test_threading", "state": "FAILED", "duration": 0.6816820999999891, "xml_data": null, "stats": {"tests_run": 1, "failures": 0, "skipped": 0}, "errors": [["test_default_timeout (test.test_threading.BarrierTests.test_default_timeout)", "Traceback (most recent call last):\n File \"D:\\a\\cpython\\cpython\\Lib\\test\\lock_tests.py\", line 1025, in test_default_timeout\n self.run_threads(f)\n File \"D:\\a\\cpython\\cpython\\Lib\\test\\lock_tests.py\", line 854, in run_threads\n f()\n File \"D:\\a\\cpython\\cpython\\Lib\\test\\lock_tests.py\", line 1020, in f\n i = barrier.wait()\n ^^^^^^^^^^^^^^\n File \"D:\\a\\cpython\\cpython\\Lib\\threading.py\", line 709, in wait\n self._wait(timeout)\n File \"D:\\a\\cpython\\cpython\\Lib\\threading.py\", line 747, in _wait\n raise BrokenBarrierError\nthreading.BrokenBarrierError\n"]], "failures": [], "__test_result__": "TestResult"}
A�s�s�e�r�t�i�o�n� �f�a�i�l�e�d�:� �t�s�t�a�t�e�_�i�s�_�a�l�i�v�e�(�t�s�t�a�t�e�)� �&�&� �!�t�s�t�a�t�e�-�>�_�s�t�a�t�u�s�.�b�o�u�n�d�,� �f�i�l�e� �D�:�\�a�\�c�p�y�t�h�o�n�\�c�p�y�t�h�o�n�\�P�y�t�h�o�n�\�p�y�s�t�a�t�e�.�c�,� �l�i�n�e� �2�4�5�
�Fatal Python error: Aborted
Thread 0x0000186c (most recent call first):
<no Python frame>
1 test failed again:
test_threading
Note also UTF-16 in logs, but this is other issue.
It only happened in Windows (x86) run, the run on Windows (x64) passed successfully, as well as on other platforms. It may be 32-bit Windows specific or random.
Linked PRs
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
OS-windowstype-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump
Projects
- StatusShow more project fieldsDone
Activity
terryjreedy commentedon Sep 6, 2023
Running just
python -m test -v test_threading(main) on my Win10 gives different newish and reproducible failures.vstinner commentedon Sep 7, 2023
I'm able to reproduce the issue on Windows 11 with Python built in 32-bit mode. See
Assertion failed: tstate_is_alive(tstate)in my logs.It seems like the assertion error requires precise timing to be triggered.
Output (reformatted for readability):
vstinner commentedon Sep 8, 2023
The test_default_timeout() failured with the
Warning -- Unraisable exceptionlog can be reproduced on Linux by stressing the machine with many processes, way more than the number of CPUs.Example of my laptop with 12 thread (6 CPU cores):
pythongh-108987: Fix _thread.start_new_thread() race condition
pythongh-108987: Fix _thread.start_new_thread() race condition
pythongh-108987: Fix _thread.start_new_thread() race condition
pythongh-108987: Fix _thread.start_new_thread() race condition
pythongh-108987: Fix _thread.start_new_thread() race condition
vstinner commentedon Sep 10, 2023
Oh, the GitHub Action Windows x64 job is also affected by this bug.
Log reformatted to make them more readable (I removed NUL bytes, add empty lines):
I had to download logs manually and remove null bytes, the two assertion errors are written in UTF-16 in a 8-bit console, and so the log is full of NUL bytes. I removed these NUL bytes.
By the way, the regrtest final report is a little bit surprising.
First, 2 tests failed:
Then, these 2 tests were run again. But test_threading crashed, regrtest failed to get the JSON from the output which is polluted by assertion errors. In that case, regrtest kills other worker processes, and stops immediately.
The surprised part is that the final report lists
test.test_concurrent_futures.test_as_completedin omitted tests:It's not obvious that something was badly wrong in the re-run step.
gh-108987: Fix _thread.start_new_thread() race condition (#109135)
pythongh-108987: Fix _thread.start_new_thread() race condition (pytho…
[3.11] gh-108987: Fix _thread.start_new_thread() race condition (#109135
vstinner commentedon Sep 14, 2023
I modified regrtest to fail with exit code 5 when a test fails and then pass when re-run: new
--fail-reunoption (it's disabled by default). I modified buildbot configuration to use--fail-rerunoption on the Python main branch.For example, a recent Windows10 job is now marked as WARNINGS (orange) because test_threading.test_default_timeout() failed and then passed when re-run in verbose mode in a fresh process.
vstinner commentedon Sep 14, 2023
This issue is about 3 things:
I prefer to stick this issue to the crash.
I created a new issue #109401 about the last points, random test failure and "Unraisable exception".
The crash is now fixed in 3.11 and main branhches. I'm waiting until #109133 backport is merged into 3.12 to be able to backport #109135 to 3.12. @Yhg1s decided that this fix has to wait for Python 3.12.1, so once the 3.12 branch will be reopened after Python 3.12.0 final release ("3.12.0 final: Monday, 2023-10-02" says PEP 693).
For now, I prefer to close this issue.
pythongh-108987: Fix _thread.start_new_thread() race condition (pytho…
[3.12] gh-108987: Fix _thread.start_new_thread() race condition (#109135