8000 gh-127421: Fix race in test_start_new_thread_failed by mpage · Pull Request #127549 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-127421: Fix race in test_start_new_thread_failed #127549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 3, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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.
  • Loading branch information
mpage committed Dec 3, 2024
commit 7778368fd3eb6dca92a9a442141671f8218234c4
3 changes: 2 additions & 1 deletion Lib/test/test_threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -1192,11 +1192,12 @@ def f():
resource.setrlimit(resource.RLIMIT_NPROC, (0, hard))

try:
_thread.start_new_thread(f, ())
handle = _thread.start_joinable_thread(f)
except RuntimeError:
print('ok')
else:
print('!skip!')
handle.join()
"""
_, out, err = assert_python_ok("-u", "-c", code)
out = out.strip()
Expand Down
Loading
0