gh-143620: Fix race condition in test_traceback_when_child_process_terminates_abruptly by a12k · Pull Request #143621 · python/cpython · GitHub
Skip to content

gh-143620: Fix race condition in test_traceback_when_child_process_terminates_abruptly - #143621

Open
a12k wants to merge 1 commit into
python:mainfrom
a12k:flaky-process-pool-test
Open

a12k wants to merge 1 commit into
python:mainfrom
a12k:flaky-process-pool-test

Conversation

@a12k

@a12k a12k commented Jan 9, 2026

Copy link
Copy Markdown
Contributor

Fixes gh-143620

There is a race condition in test_concurrent_futures.test_process_pool. The test asserts that a BrokenProcessPool exception has a __cause__ immediately after future.result() raises.

In concurrent.futures.process, the _terminate_broken method sets the exception on the future before it attaches the _RemoteTraceback to the __cause__ attr. Sometimes the test thread wakes up and inspects the exception while __cause__ is still None, which leads to a test failure. I was able to repro (see issue for more details) by injecting a delay in _terminate_broken between the set_exception() call and the __cause__ assignment. This causes a 100% failure rate with AssertionError: None is not an instance of _RemoteTraceback.

My proposed fix is to update the test to use support.sleeping_retry to wait for the __cause__ to be populated. This seems to be the pattern elsewhere in the test suite.

@WYSIATI

WYSIATI commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

@github-actions

github-actions Bot commented May 4, 2026

Copy link
Copy Markdown

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review stale Stale PR or inactive for long period of time. tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Race condition in test_traceback_when_child_process_terminates_abruptly

2 participants