René's URL Explorer Experiment


Title: C stack limit detection is disabled on musl, so deep C recursion crashes instead of raising RecursionError · Issue #159876 · python/cpython · GitHub

Open Graph Title: C stack limit detection is disabled on musl, so deep C recursion crashes instead of raising RecursionError · Issue #159876 · python/cpython

X Title: C stack limit detection is disabled on musl, so deep C recursion crashes instead of raising RecursionError · Issue #159876 · python/cpython

Description: Bug report Bug description: On Alpine Linux (musl libc), test_lazy_import.LazyImportTypeTests.test_deeply_dotted_name terminates the interpreter with SIGSEGV instead of raising RecursionError: $ ./python -m unittest test.test_lazy_import...

Open Graph Description: Bug report Bug description: On Alpine Linux (musl libc), test_lazy_import.LazyImportTypeTests.test_deeply_dotted_name terminates the interpreter with SIGSEGV instead of raising RecursionError: $ ./...

X Description: Bug report Bug description: On Alpine Linux (musl libc), test_lazy_import.LazyImportTypeTests.test_deeply_dotted_name terminates the interpreter with SIGSEGV instead of raising RecursionError: $ ./...

Opengraph URL: https://github.com/python/cpython/issues/159876

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"C stack limit detection is disabled on musl, so deep C recursion crashes instead of raising RecursionError","articleBody":"# Bug report\n\n### Bug description:\n\nOn Alpine Linux (musl libc), `test_lazy_import.LazyImportTypeTests.test_deeply_dotted_name` terminates the\ninterpreter with SIGSEGV instead of raising `RecursionError`:\n\n```\n$ ./python -m unittest test.test_lazy_import.LazyImportTypeTests.test_deeply_dotted_name\ntest_deeply_dotted_name (...)\nA long dotted name must not overflow the C stack. ... Segmentation fault\n```\n\nThe crash is a C stack overflow in the prologue of a recursive call:\n\n```\nThread 2 \"Thread-1 (run)\" received signal SIGSEGV, Segmentation fault.\n0x00005555556bc2dc in lazy_import_replay_from (...) at ../Objects/lazyimportobject.c:280\n#1  0x00005555556bc331 in lazy_import_replay_from (...) at ../Objects/lazyimportobject.c:287\n#2  0x00005555556bc331 in lazy_import_replay_from (...) at ../Objects/lazyimportobject.c:287\n... (repeats)\n```\n\n`lazy_import_replay_from()` does guard itself with `_Py_EnterRecursiveCallTstate()`, so the guard is simply\nnot firing.\n\n#### Cause\n\nThe test runs its body in a thread with a 256 KiB stack\n(`@support.run_with_limited_c_stack(depth=10_000, size=256 * 1024)`), but CPython never learns that.\n`hardware_stack_limits()` in `Python/ceval.c` only queries the real stack bounds when:\n\n```c\n#  if defined(HAVE_PTHREAD_GETATTR_NP) && !defined(_AIX) && \\\n        !defined(__NetBSD__) && \\\n        (defined(__GLIBC__) || defined(__ANDROID__) || !defined(__linux__))\n```\n\n(`Python/ceval.c:150-152` on main, `:162-164` on 3.15, `:462-464` on 3.14.)\n\nOn musl, `__linux__` is defined while `__GLIBC__` and `__ANDROID__` are not, so the probe is skipped and\nCPython falls back to guessing `base = sp - Py_C_STACK_SIZE`. With the `-Wl,-z,stack-size=` that configure\nadds, `Py_C_STACK_SIZE` is `_Py_LINKER_THREAD_STACK_SIZE` = 1048576, so **the interpreter assumes 1 MiB on\nevery thread regardless of the thread's real size**.\n\nMeasured with `_testinternalcapi.get_c_recursion_remaining()`:\n\n```python\nimport threading, _testinternalcapi as T\nfor size in (256 * 1024, 8 * 1024 * 1024):\n    threading.stack_size(size)\n    def show(size=size):\n        print(\"  thread stack %7d B -> c_recursion_remaining=%d\"\n              % (size, T.get_c_recursion_remaining()))\n    t = threading.Thread(target=show); t.start(); t.join()\n```\n\n```\nAlpine 3.24 / musl:  thread stack  262144 B -> c_recursion_remaining=1450\n                     thread stack 8388608 B -> c_recursion_remaining=1450   # constant\nDebian / glibc:      thread stack  262144 B -> c_recursion_remaining=250\n                     thread stack 8388608 B -> c_recursion_remaining=12650  # tracks reality\n```\n\nSo on a 256 KiB thread the interpreter believes it has roughly 4x the stack it actually has, the soft limit\nlands below the real stack base, and the guard can never trigger.\n\n#### The exclusion looks broader than the problem it was added for\n\nIt came from GH-134336 (\"Disable computed stack limit checks on non-glibc linux\", gh-131338). But musl's\n`pthread_getattr_np()` is accurate for secondary threads and only wrong for the **main** thread:\n\n```c\n/* cc -o stackprobe stackprobe.c */\n#define _GNU_SOURCE\n#include \u003cpthread.h>\n#include \u003cstdio.h>\nstatic void report(const char *tag) {\n    pthread_attr_t attr; void *addr = NULL; size_t size = 0, guard = 0;\n    if (pthread_getattr_np(pthread_self(), &attr)) { printf(\"%s: failed\\n\", tag); return; }\n    pthread_attr_getstack(&attr, &addr, &size);\n    pthread_attr_getguardsize(&attr, &guard);\n    pthread_attr_destroy(&attr);\n    printf(\"%-14s base=%p size=%zu (%.2f MiB) guard=%zu\\n\", tag, addr, size, size/1048576.0, guard);\n}\nstatic void *thr(void *a) { report((const char *)a); return NULL; }\nint main(void) {\n    pthread_attr_t a; pthread_t t;\n    report(\"main\");\n    pthread_attr_init(&a); pthread_attr_setstacksize(&a, 8u\u003c\u003c20);\n    pthread_create(&t, &a, thr, (void *)\"thread-8MiB\"); pthread_join(t, NULL);\n    pthread_attr_destroy(&a);\n    pthread_create(&t, NULL, thr, (void *)\"thread-default\"); pthread_join(t, NULL);\n    return 0;\n}\n```\n\n```\nAlpine 3.24 / musl 1.2:\nmain           base=0x7ffeda154000 size=131072 (0.12 MiB) guard=0        \u003c-- wrong, RLIMIT_STACK is 8 MiB\nthread-8MiB    base=0x7f772ee70000 size=8391456 (8.00 MiB) guard=8192    \u003c-- correct\nthread-default base=0x7f772f650000 size=133920  (0.13 MiB) guard=8192    \u003c-- correct\n\nDebian / glibc 2.41:\nmain           base=0x7fffa3c90000 size=8380416 (7.99 MiB) guard=0\nthread-8MiB    base=0x7909e3800000 size=8388608 (8.00 MiB) guard=4096\nthread-default base=0x7909e3800000 size=8388608 (8.00 MiB) guard=4096\n```\n\nThis is the same shape as gh-159320 / GH-159321, which re-enabled detection for Android after it had been\ncaught by the same blanket condition.\n\n#### Scope\n\nThe broken detection is not specific to `test_lazy_import` or to 3.15+: the guard is identical on 3.14, and\nthe probe above returns the same constant 1450 on a 3.14 build. 3.14 is only green because\n`test_lazy_import` does not exist there and no other test asks for a thread smaller than the assumed\n`Py_C_STACK_SIZE`. Any embedder or stdlib caller creating a musl thread with less than ~1 MiB of stack can\noverflow silently.\n\nApart from this one test, the suite is clean on Alpine: `main` 550 test files run / 1 failed, `3.15` 548 /\n1 failed (same test), `3.14` 525 / 0 failed.\n\nI appreciate musl is PEP 11 tier 0 (configure says so explicitly) and that gh-151546, gh-139467 and gh-76488\nwere all closed as `OS-unsupported`. Filing this one anyway because it is a hard crash where a guard exists\nand is expected to work, and because the Android case was treated as worth fixing.\n\n### CPython versions tested on:\n\n3.14, 3.15, CPython main branch\n\n### Operating systems tested on:\n\nLinux\n\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-159882\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/serhiy-storchaka","@type":"Person","name":"serhiy-storchaka"},"datePublished":"2026-10-20T12:30:49Z","url":"https://github.com/python/cpython/issues/159876"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:a684f1ef-8202-65be-7073-094930af13d1
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idAA90:11EACE:36A42D3:48EA299:6B020B54
html-safe-nonce5d47faed80cc89f636a0e46b996acf2ef884b719234d3230ce061b59edcb1cf7
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQTkwOjExRUFDRTozNkE0MkQzOjQ4RUEyOTk6NkIwMjBCNTQiLCJ2aXNpdG9yX2lkIjoiMzk4NTMzOTQ5NzY1NDEyNzQ0NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacd28bcd2de72873cfbdef4e32d5889242e734711f43ecf8f15959ab1ff50cb909
hovercard-subject-tagissue:5941658517
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/159876/issue_layout
twitter:imagehttps://opengraph.githubassets.com/2078650a88f6d980ff7b044a0cbacd36ed4b2bfbe4776ea6e282bb011622c510/python/cpython/issues/159876
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/2078650a88f6d980ff7b044a0cbacd36ed4b2bfbe4776ea6e282bb011622c510/python/cpython/issues/159876
og:image:altBug report Bug description: On Alpine Linux (musl libc), test_lazy_import.LazyImportTypeTests.test_deeply_dotted_name terminates the interpreter with SIGSEGV instead of raising RecursionError: $ ./...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameserhiy-storchaka
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/cpython/issues/159876#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F159876
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F159876
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/159876
Reloadhttps://github.com/python/cpython/issues/159876
Reloadhttps://github.com/python/cpython/issues/159876
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.4k (2.4k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/insights
https://github.com/python/cpython
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/159876
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/159876
C stack limit detection is disabled on musl, so deep C recursion crashes instead of raising RecursionErrorhttps://github.com/python/cpython/issues/159876#top
3.14bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.14%22
3.15bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.15%22
3.16new features, bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.16%22
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com/serhiy-storchaka
serhiy-storchakahttps://github.com/serhiy-storchaka
on Oct 20, 2026https://github.com/python/cpython/issues/159876#issue-5941658517
1048576https://github.com/python/cpython/commit/104857670203bd03ad4ee67d31c22c09970bee5c
GH-134336https://github.com/python/cpython/pull/134336
gh-131338https://github.com/python/cpython/issues/131338
gh-159320https://github.com/python/cpython/issues/159320
GH-159321https://github.com/python/cpython/pull/159321
gh-151546https://github.com/python/cpython/issues/151546
gh-139467https://github.com/python/cpython/issues/139467
gh-76488https://github.com/python/cpython/issues/76488
gh-159876: Detect the C stack size of non-main threads on musl #159882https://github.com/python/cpython/pull/159882
https://github.com/serhiy-storchaka
serhiy-storchakahttps://github.com/serhiy-storchaka
on Oct 20, 2026https://github.com/python/cpython/issues/159876#issuecomment-6290964760
serhiy-storchakahttps://github.com/serhiy-storchaka
on Oct 20, 2026https://github.com/python/cpython/issues/159876#event-33742354474
pythongh-159876: Detect the C stack size of non-main threads on muslhttps://github.com/serhiy-storchaka/cpython/commit/ae222a3c07cc2dc96aec639575f4ba20d87f643e
pythongh-159876https://github.com/python/cpython/issues/159876
ae222a3https://github.com/serhiy-storchaka/cpython/commit/ae222a3c07cc2dc96aec639575f4ba20d87f643e
aiskhttps://github.com/aisk
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
on Oct 20, 2026https://github.com/python/cpython/issues/159876#event-33742396276
serhiy-storchakahttps://github.com/serhiy-storchaka
on Oct 20, 2026https://github.com/python/cpython/issues/159876#event-33742544070
pythongh-159876: Detect the C stack size of non-main threads on muslhttps://github.com/serhiy-storchaka/cpython/commit/42f613868056958505623137d07a4a10124baa05
pythongh-159876https://github.com/python/cpython/issues/159876
42f6138https://github.com/serhiy-storchaka/cpython/commit/42f613868056958505623137d07a4a10124baa05
serhiy-storchakahttps://github.com/serhiy-storchaka
3.14bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.14%22
3.15bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.15%22
3.16new features, bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.16%22
on Oct 20, 2026https://github.com/python/cpython/issues/159876#event-33742710642
https://github.com/vstinner
vstinnerhttps://github.com/vstinner
on Oct 22, 2026https://github.com/python/cpython/issues/159876#issuecomment-6335345355
gh-159535https://github.com/python/cpython/issues/159535
https://github.com/RECHE23
RECHE23https://github.com/RECHE23
on Nov 10, 2026https://github.com/python/cpython/issues/159876#issuecomment-6768804480
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/159876
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/159876
3.14bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.14%22
3.15bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.15%22
3.16new features, bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.16%22
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.