Skip to content

gh-159876: Detect the C stack size of non-main threads on musl - #159882

Draft
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:gh-159876-musl-stack
Draft

serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:gh-159876-musl-stack

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

hardware_stack_limits() skipped pthread_getattr_np() on any Linux that is neither glibc nor Android, because musl misreports the main thread's stack. musl is accurate for the threads it creates itself, so the blanket exclusion left the interpreter assuming Py_C_STACK_SIZE everywhere, and a thread with a smaller stack overflowed before the recursion guard fired.

Query the stack on every thread except the process main thread, which keeps the old estimate.

On Alpine 3.24 this takes c_recursion_remaining from a constant 1450 to 250 / 12650 for 256 KiB / 8 MiB threads — the same numbers glibc reports — and the full suite goes from 1 failure (a SIGSEGV in test_lazy_import) to Result: SUCCESS. No change on glibc.

🤖 Generated with Claude Code

pthread_getattr_np() was skipped on every non-glibc, non-Android Linux
because musl misreports the main thread's stack.  It is accurate for the
threads musl creates itself, so query those and keep the estimate only
for the main thread.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@serhiy-storchaka
serhiy-storchaka marked this pull request as draft October 20, 2026 12:49
@serhiy-storchaka serhiy-storchaka added needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant