]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
[3.13] gh-127421: Fix race in test_start_new_thread_failed (GH-127549) (#127574)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 3 Dec 2024 18:30:08 +0000 (19:30 +0100)
committerGitHub <noreply@github.com>
Tue, 3 Dec 2024 18:30:08 +0000 (10:30 -0800)
commit0b266aaa398b48df3918308cb5a895dd9a0651d9
treecdb58b70d590324d095cd2ebdd53ba82be1b9e0b
parentdddea7c2328d498e0e73bb8619d2a3fa1e6f190e
[3.13] gh-127421: Fix race in test_start_new_thread_failed (GH-127549) (#127574)

gh-127421: Fix race in test_start_new_thread_failed (GH-127549)

Fix race in test_start_new_thread_failed

When we succeed in starting a new thread, for example if setrlimit
was ineffective, we must wait for the newly spawned thread to exit.
Otherwise, we run the risk that the newly spawned thread will race
with runtime finalization and access memory that has already been
clobbered/freed.

`_thread.start_new_thread()` only spawns daemon threads, which the runtime
does not wait for at shutdown, and does not return a handle. Use
`_thread.start_joinable_thread()` and join the resulting handle when
the thread is started successfully.
(cherry picked from commit 13b68e1a61e92a032d255aff5d5af435bbb63e8b)

Co-authored-by: mpage <mpage@meta.com>
Lib/test/test_threading.py