Skip to content

gh-131338: Disable new stack size code for non-glibc on linux. #134336

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

bitdancer
Copy link
Member

@bitdancer bitdancer commented May 20, 2025

MUSL claims to support pthread_getattr_np, but the response returned is off by at least an order of magnitude compared to reality. This is apparently a long standing problem. MUSL also does not provide any way to detect directly that it is the libc. It would be possible to add things to configure to detect that MUSL is the compiler, but since this code has apparently caused problems for a lot of non-glibc platforms, it seems easier to just restrict it to glibc.

MUSL claims to support pthread_getattr_np, but the response returned is
off by at least an order of magnitude compared to reality.  This is
apparently a long standing problem.  MUSL also does not provide any way
to detect directly that it is the libc.  It would be possible to add
things to configure to detect that MUSL is the compiler, but since this
code has caused problems for a lot of non-glibc platforms, it seems
easier to just restrict it to glibc.
Python/ceval.c Outdated
@@ -442,7 +442,8 @@ _Py_InitializeRecursionLimits(PyThreadState *tstate)
_tstate->c_stack_soft_limit = _tstate->c_stack_hard_limit + PYOS_STACK_MARGIN_BYTES;
#else
uintptr_t here_addr = _Py_get_machine_stack_pointer();
# if defined(HAVE_PTHREAD_GETATTR_NP) && !defined(_AIX) && !defined(__NetBSD__)
# if defined(HAVE_PTHREAD_GETATTR_NP) && !defined(_AIX) && \
!defined(__NetBSD__) && defined(__GLIBC__)
Copy link
Member

Choose a reason for hiding this comment

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

I don't think that this call is correct. It disables the call on FreeBSD.

Maybe check for "glibc or not Linux"?

Copy link
Member Author

Choose a reason for hiding this comment

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

That would fix it for alpine, but not for emscripten or wasi (but I don't know what they actually need). I'd rather see it as if glibc or freebsd, and get rid of the rest, but glibc or not linux would work for my immediate concern.

Copy link
Member

Choose a reason for hiding this comment

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

Well, let's start with fixing Alpine Linux.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, done. Also added an XXX comment, since I think this needs more investigation. I'll put it on my todo list to post to the musl mailing list about it.

This exempts alpine but doesn't affect, eg, FreeBSD.
@bitdancer bitdancer changed the title gh-131338: Disable new stack size code for non-glibc. gh-131338: Disable new stack size code for non-glibc on linux. Jun 15, 2025
Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

LGTM

@kumaraditya303 kumaraditya303 added the needs backport to 3.14 bugs and security fixes label Jun 21, 2025
@kumaraditya303
Copy link
Contributor

This looks good but it needs a news entry as it is a bugfix and needs to be backported to 3.14.

@kumaraditya303 kumaraditya303 added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Jun 25, 2025
kumaraditya303 and others added 2 commits July 25, 2025 22:22
Co-authored-by: Victor Stinner <vstinner@python.org>
@kumaraditya303
Copy link
Contributor

I have added a news entry to move this PR forward and get this merged soon, will run through buildbots and merge.

@kumaraditya303 kumaraditya303 added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Jul 25, 2025
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @kumaraditya303 for commit 6498d29 🤖

Results will be shown at:

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

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Jul 25, 2025
ngoldbaum added a commit to ngoldbaum/cpython that referenced this pull request Jul 25, 2025
@ngoldbaum
Copy link
Contributor

Kumar asked me to test libcst with this PR applied. I manually backported the substantive part of this PR to the 3.14 branch and built Python using pyenv in the musllinux docker container.

I still see the segfault: https://gist.github.com/ngoldbaum/16fb37188d049edcd18296f809241798.

Also looking close, I don't think the crash we saw in LibCST is caused by this, since we see it in 3.13, and I don't think the new stack size code ever went into 3.13?

@kumaraditya303
Copy link
Contributor

Also looking close, I don't think the crash we saw in LibCST is caused by this, since we see it in 3.13, and I don't think the new stack size code ever went into 3.13?

Yes, it is present in 3.14 and above. Looking at the backtrace of libcst it seems unrelated to this, a better test candidate for this would be scipy as that currently errors out with RecursionError like in scipy/scipy#23172.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting merge interpreter-core (Objects, Python, Grammar, and Parser dirs) needs backport to 3.14 bugs and security fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy