Fix stack overflow segfault on debug builds for Python threads#7986
Fix stack overflow segfault on debug builds for Python threads#7986JamesClarke7283 wants to merge 2 commits into
Conversation
Rust's std::thread::Builder defaults to a 2 MB stack when no size is
set, which is too small for the call chains the Python stdlib runs on
helper threads in debug builds (e.g. test.test_ssl's threaded server).
CPython on glibc Linux relies on pthread's ~8 MB default instead.
Apply 8 MB as the default in apply_thread_stack_size when the user has
not explicitly called threading.stack_size(N). This matches CPython's
effective default across builds while preserving the existing API:
threading.stack_size() still returns 0 by default ("platform default"),
and explicit user values still take precedence.
Fixes RustPython#7941
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughapply_thread_stack_size now always sets the thread builder's stack size: it uses ChangesThread Stack Sizing
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Satisfy docstring coverage check on the PR. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Summary
std::thread::Builderdefault stack of 2 MB, which is too small for the call chains the Python stdlib runs on helper threads in debug builds (where Rust stack frames are substantially larger). CPython on glibc Linux relies on pthread's ~8 MB default instead — a 4× difference that explains why this hits us but not CPython.apply_thread_stack_sizewhenever the user hasn't explicitly set a value viathreading.stack_size(N). This matches CPython's effective default while keeping the Python API contract exact:threading.stack_size()still returns0("platform default"), and explicit overrides still take precedence.crates/vm/src/stdlib/_thread.rs.Closes #7941
Test plan
cargo buildsucceeds.cargo run -- -m test.test_ssl ThreadedTests.test_socketserver→Ran 1 test in 21.59s, OK(was segfaulting onmain).threading.stack_size()returns0by default; setting to 1 MiB then reading back returns1048576; previous value reported correctly.🤖 Generated with Claude Code
Summary by CodeRabbit