Skip to content

gh-159320: use pthread_getattr_np for stack limit checks even on musl - #161749

Merged
encukou merged 14 commits into
python:mainfrom
encukou:musl-stack-check
Nov 27, 2026
Merged

encukou merged 14 commits into
python:mainfrom
encukou:musl-stack-check

Conversation

@encukou

@encukou encukou commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

This builds on @Yhg1s's #159376, trying some more things:

  • Report unreliable_pthread_getattr_np even if configure runs with unlimited stack, by limiting it artificially.
  • Adjust the base, not the top
@encukou

encukou commented Nov 10, 2026

Copy link
Copy Markdown
Member Author

!buildbot Alpine

@bedevere-bot

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @encukou for commit 7b773d3 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F161749%2Fmerge

The command will test the builders whose names match following regular expression: Alpine

The builders matched are:

  • AMD64 Alpine Linux NoGIL PR
  • AMD64 Alpine Linux PR
@encukou

encukou commented Nov 12, 2026

Copy link
Copy Markdown
Member Author

This fixes the test_lazy_import failure; the remaining test_profiling one looks unrelated.
@vstinner or @Yhg1s, does the code look reasonable?

@aozmekik aozmekik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on Alpine 3.22 (musl) x86_64 and aarch64, debug build, against the merge base:

  • configure sets _Py_HAVE_UNRELIABLE_PTHREAD_GETATTR_NP on both.
  • Main thread get_c_recursion_remaining(): 1450 -> 12650 with ulimit -s 8192 (same as glibc), 102250 with 64 MiB, and still 1450 with an unlimited stack. New threads stay at 1450.
  • test_lazy_import, test_typing, test_json, test_ast, test_compile, test_exceptions, test_pickle and test_threading pass; one of them fails on the merge base.

Nit: on musl configure prints checking whether pthread_getattr_np reports the main thread stack reliably... yes, since the cached value is the inverse. Also, cross builds default to no, so a musl cross build keeps the old limit unless ac_cv_unreliable_pthread_getattr_np=yes is passed. Might be worth defaulting from $host there.

@encukou

encukou commented Nov 27, 2026

Copy link
Copy Markdown
Member Author

I'll merge to (hopefully) fix the buildbot.

@encukou
encukou merged commit 235d138 into python:main Nov 27, 2026
140 of 159 checks passed
@encukou encukou added the needs backport to 3.15 bugs and security fixes label Nov 27, 2026
@miss-islington-app

Copy link
Copy Markdown

Thanks @encukou for the PR 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

@miss-islington-app

Copy link
Copy Markdown

Sorry, @encukou, I could not cleanly backport this to 3.15 due to a conflict.

Please backport manually with cherry_picker, see the devguide for more information.

cherry_picker 235d1383333bd36d15290de03a98c25f1a2fd109 3.15
@bedevere-app

bedevere-app Bot commented Nov 28, 2026

Copy link
Copy Markdown

GH-162819 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Nov 28, 2026
encukou added a commit that referenced this pull request Nov 30, 2026
…on musl (GH-161749) (GH-162819)

Rewrite the pthread_getattr_np usage to avoid the problem on musl of it
reporting the stack limit of the main thread incorrectly. On platforms where
pthread_getattr_np underreports the main thread's stack size, use
RLIMIT_STACK for the main thread instead.

Add HAVE_UNRELIABLE_PTHREAD_GETATTR_NP to the long, long list of ignored
symbols for the Py check.

Authored mainly by: Thomas Wouters
(cherry picked from commit 235d138)


Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Thomas Wouters <thomas@python.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants