GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-148260: Use at least 1 MiB stack size on musl by vstinner · Pull Request #149993 · python/cpython

Conversation

@vstinner

@vstinner vstinner commented May 18, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

On Linux when Python is linked to the musl C library, use a thread stack size of at least 1 MiB instead of musl default which is 128 kiB.

  • Issue: test_threading.test_recursion_limit() does crash (segfault) on Alpine Linux (musl) #148260

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@vstinner
pythongh-148260: Use at least 1 MiB stack size on musl
fd078ac
On Linux when Python is linked to the musl C library, use a thread
stack size of at least 1 MiB instead of musl default which is 128
kiB.
@vstinner
vstinner requested review from AA-Turner, corona10, emmatyping and erlend-aasland as code owners May 18, 2026 14:02
@bedevere-app bedevere-app Bot mentioned this pull request May 18, 2026
test_threading.test_recursion_limit() does crash (segfault) on Alpine Linux (musl) #148260
Closed
@bedevere-app bedevere-app Bot added the awaiting core review label May 18, 2026
@vstinner

vstinner commented May 18, 2026

Copy link
Copy Markdown
Member Author

On "AMD64 Alpine Linux NoGIL 3.x" buildbot, currently test_threading.test_recursion_limit() does crash with a stack overflow: issue gh-148260.

With this change, Python is built with -Wl,-z,stack-size=1048576 linker flag and so uses a thread stack size of 1 MiB by default, instead of musl default which is 128 kiB.

With this change, test_threading.test_recursion_limit() does pass. I tested Python built in debug mode (gcc -O3) and release mode (gcc -Og), with and without the GIL (--disable-gil). The buildbot worker uses ./configure --with-pydebug --disable-gil.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented May 18, 2026

Copy link
Copy Markdown
Member Author

@corona10 @erlend-aasland @picnixz: I'm looking for autotools experts to review my configure.ac change. I'm not comfortable with changing the build system.

Currently, the ./configure script doesn't run a built C program, it only uses AC_LINK_IFELSE or AC_COMPILE_IFELSE to check if a C program can be built or linked.

It seems like running a program is the only way to check if Python is linked to the musl library. My change is not specific to the musl library, but instead read the default thread stack size to decide if -Wl,-z,stack-size=1048576 linker flag should be used.

My configure.ac is inspired by Python 3.12 ./configure script which runs $CPP $CPPFLAGS conftest.c >conftest.out to read the output of the C preprocessor. But my change is different since it compiles a C program and then runs the C program. The code is skipped if Python is cross-compiled.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

vstinner
vstinner commented May 18, 2026
View reviewed changes
Comment thread configure.ac
EOF

ac_cv_thread_stack_size="default"
if $CC -pthread $CFLAGS conftest.c -o conftest &>/dev/null; then

@vstinner vstinner May 18, 2026

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I chose to use $CC -pthread to make sure that the pthread API can be used in the C program. We check if -pthread is supported above, near line 3064, which sets CC="$CC -pthread" if the flag is supported. I should maybe omit -pthread and move my code after the -pthread check.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@Yhg1s Yhg1s May 18, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I think using -pthread explicitly is fine, it doesn't matter if it's passed to the compiler twice.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

vstinner and gpshead reacted with thumbs up emoji
All reactions
  • 👍 2 reactions
@zware

zware commented May 18, 2026

Copy link
Copy Markdown
Member

!buildbot Alpine

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot

bedevere-bot commented May 18, 2026

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @zware for commit fd078ac 🤖

Results will be shown at:

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

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

The builders matched are:

  • AMD64 Alpine Linux PR
  • AMD64 Alpine Linux NoGIL PR
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented May 18, 2026

Copy link
Copy Markdown
Member Author

Cool, the test suite passed on Alpine Linux buildbots:

buildbot/AMD64 Alpine Linux NoGIL PR — Build done.
buildbot/AMD64 Alpine Linux PR — Build done.

zware reacted with thumbs up emoji zware reacted with hooray emoji
All reactions
  • 👍 1 reaction
  • 🎉 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Yhg1s
Yhg1s approved these changes May 18, 2026
View reviewed changes
Comment thread configure.ac
EOF

ac_cv_thread_stack_size="default"
if $CC -pthread $CFLAGS conftest.c -o conftest &>/dev/null; then

@Yhg1s Yhg1s May 18, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I think using -pthread explicitly is fine, it doesn't matter if it's passed to the compiler twice.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

vstinner and gpshead reacted with thumbs up emoji
All reactions
  • 👍 2 reactions
Comment thread configure.ac Outdated
ac_cv_thread_stack_size="default"
if $CC -pthread $CFLAGS conftest.c -o conftest &>/dev/null; then
./conftest &>/dev/null
if test $? -eq 1; then

@Yhg1s Yhg1s May 18, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

For debugging it would probably be nice if the output said whether the stack size is good enough, needs overriding or just unknown (return code 2)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@vstinner vstinner May 18, 2026

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

The possible exit codes are:

  • 0: the thread stack is at least 1 MiB
  • 1: the thread stack is less than 1 MiB
  • 2: an error occurred

The two possible outputs are:

  • checking for thread stack size... default if the stack size is already at least 1 MiB
  • checking for thread stack size... 1048576 if the stack size must be set to 1 MiB with LDFLAGS

Do you mean that the error case should be rendered differently, such as "error"? Usually, it seems like configure ignores errors silently.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@Yhg1s Yhg1s May 18, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I mean I would like the output to be "checking for the thread stack size... unknown". It can keep behaving like 'default', but at least from the configure output it'll be more obvious it wasn't able to detect the actual thread size. But it's not a big deal if it's too tricky to get right.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@vstinner vstinner May 18, 2026

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Ok, I modified the code to display "error" if gcc/clang failed to build the C program, or if the C program failed (exit code differently than 0 and 1).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels May 18, 2026
@vstinner
Display "unknown" on error
86027a6
@vstinner

vstinner commented May 19, 2026

Copy link
Copy Markdown
Member Author

!buildbot Alpine

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot

bedevere-bot commented May 19, 2026

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @vstinner for commit 86027a6 🤖

Results will be shown at:

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

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

The builders matched are:

  • AMD64 Alpine Linux PR
  • AMD64 Alpine Linux NoGIL PR
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@zware

zware commented May 19, 2026

Copy link
Copy Markdown
Member

buildbot Alpine

The worker is down at the moment; I had a storm-related power outage this morning and my UPS has not yet recharged enough to turn the host back on. It will be back by this afternoon.

vstinner and encukou reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented May 20, 2026

Copy link
Copy Markdown
Member Author

buildbot/AMD64 Alpine Linux NoGIL PR
buildbot/AMD64 Alpine Linux PR

It works as expected:

  • configure log: checking for thread stack size... 1048576.
  • compile log: gcc -shared -Wl,-z,stack-size=1048576 Modules/arraymodule.o -o Modules/array.cpython-316td-x86_64-linux-musl.so
  • tests: test_threading passed

On "AMD64 Alpine Linux NoGIL PR", test_threading crashed :-( But it passed when rerun...

0:03:47 load avg: 6.33 [255/505/1] test_threading worker non-zero exit code (Exit code -11 (SIGSEGV)) -- running (1): test_compileall (30.8 sec)

(...)
test_start_thread_again (test.test_threading.ThreadingExceptionTests.test_start_thread_again) ... ok
test_concurrent_tee_negative_n (test.test_threading.ThreadingIteratorToolsTests.test_concurrent_tee_negative_n) ... ok
test_concurrent_tee_supports_concurrent_consumers (test.test_threading.ThreadingIteratorToolsTests.test_concurrent_tee_supports_concurrent_consumers) ...
(...)
0:08:02 load avg: 3.48 Run 1 test in parallel using 1 worker process (timeout: 30 min, worker timeout: 35 min)
0:08:26 load avg: 2.66 [1/1] test_threading passed
(...)
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner
vstinner merged commit df6c157 into python:main May 20, 2026
52 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@vstinner
vstinner deleted the musl_stack_size branch May 20, 2026 11:22
@bedevere-app bedevere-app Bot removed the awaiting merge label May 20, 2026
@vstinner vstinner added the needs backport to 3.15 bugs and security fixes label May 20, 2026
@miss-islington-app

miss-islington-app Bot commented May 20, 2026

Copy link
Copy Markdown

Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app

bedevere-app Bot commented May 20, 2026

Copy link
Copy Markdown

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label May 20, 2026
vstinner added a commit that referenced this pull request May 20, 2026
@miss-islington @vstinner
[3.15] gh-148260: Use at least 1 MiB stack size on musl (GH-149993) (#…
c555e26
…150150)

gh-148260: Use at least 1 MiB stack size on musl (GH-149993)

On Linux when Python is linked to the musl C library, use a thread
stack size of at least 1 MiB instead of musl default which is 128
kiB.
(cherry picked from commit df6c157)

Co-authored-by: Victor Stinner <[email protected]>
@markshannon markshannon mentioned this pull request May 21, 2026
GH-126910: Make _Py_get_machine_stack_pointer return the actual stack pointer #149103
Merged
@vstinner vstinner added the needs backport to 3.14 bugs and security fixes label Jun 17, 2026
@miss-islington-app

miss-islington-app Bot commented Jun 17, 2026

Copy link
Copy Markdown

Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app

bedevere-app Bot commented Jun 17, 2026

Copy link
Copy Markdown

GH-151586 is a backport of this pull request to the 3.14 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Jun 17, 2026
vstinner added a commit that referenced this pull request Jun 17, 2026
@miss-islington @vstinner
[3.14] gh-148260: Use at least 1 MiB stack size on musl (GH-149993) (#…
5516672
…151586)

gh-148260: Use at least 1 MiB stack size on musl (GH-149993)

On Linux when Python is linked to the musl C library, use a thread
stack size of at least 1 MiB instead of musl default which is 128
kiB.
(cherry picked from commit df6c157)

Co-authored-by: Victor Stinner <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@Yhg1s Yhg1s Yhg1s approved these changes
@erlend-aasland erlend-aasland Awaiting requested review from erlend-aasland erlend-aasland is a code owner
@corona10 corona10 Awaiting requested review from corona10 corona10 is a code owner
@AA-Turner AA-Turner Awaiting requested review from AA-Turner AA-Turner is a code owner
@emmatyping emmatyping Awaiting requested review from emmatyping emmatyping is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@vstinner @zware @bedevere-bot @Yhg1s
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.