René's URL Explorer Experiment


Title: gh-149146: Add dealloc-depth counter fallback to trashcan trigger by bhuvi27 · Pull Request #151595 · python/cpython · GitHub

Open Graph Title: gh-149146: Add dealloc-depth counter fallback to trashcan trigger by bhuvi27 · Pull Request #151595 · python/cpython

X Title: gh-149146: Add dealloc-depth counter fallback to trashcan trigger by bhuvi27 · Pull Request #151595 · python/cpython

Description: Fixes #149146. while True: b = (b, None) under RLIMIT_AS segfaults during cleanup: b = 9 while True: b = (b, None) Docker with ulimit -v 524288: MemoryError → lost sys.stderr → segfault, exit 139. The trashcan deposit in _Py_Dealloc only fires when _Py_RecursionLimit_GetMargin(tstate) < 2, which compares the stack pointer against c_stack_soft_limit. Under RLIMIT_AS the kernel SIGSEGVs trying to grow the stack while SP is still nowhere near the soft limit — issue #150722 has an LLDB trace from the same reporter showing SP ~7 MB above c_stack_hard_limit at the fault. So the trashcan never deposits and the recursive tuple_dealloc → Py_XDECREF → _Py_Dealloc → tuple_dealloc chain just runs into the wall. This adds a per-thread c_dealloc_depth counter and uses it as a secondary trigger inside _Py_Dealloc, depositing at depth 50 (matches the old _PyTrash_UNWIND_LEVEL). The stack-pointer margin stays the primary signal; the counter only kicks in when SP can't. One thing I missed on the first pass: the drain side has the same problem. margin >= 4 is also true in this scenario, so every _Py_Dealloc exit would re-enter _PyTrash_thread_destroy_chain from inside the deallocator it just called. Fix: destroy_chain bumps the counter for the duration of the drain (same idea as the old delete_nesting), and the drain check in _Py_Dealloc becomes just c_dealloc_depth == 0. Counter is only touched for GC types so non-GC types pay nothing. Tests: new test_trashcan_nested_tuple_deep in test_gc.py (100k nested tuples, must clean up without crash); test_gc test_exceptions test_capi all green locally. Docker repro now exits 1 with MemoryError instead of 139 with Segmentation fault. #150722 is the same SP-signal blindness in the comparison path (Py_EnterRecursiveCall) — separate code path, separate PR.

Open Graph Description: Fixes #149146. while True: b = (b, None) under RLIMIT_AS segfaults during cleanup: b = 9 while True: b = (b, None) Docker with ulimit -v 524288: MemoryError → lost sys.stderr → segfault, exit 1...

X Description: Fixes #149146. while True: b = (b, None) under RLIMIT_AS segfaults during cleanup: b = 9 while True: b = (b, None) Docker with ulimit -v 524288: MemoryError → lost sys.stderr → segfault, exit 1...

Opengraph URL: https://github.com/python/cpython/pull/151595

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:9c3a4a5e-0db4-1491-933d-299c9ac6cf4a
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idAC4E:25F3E7:261A3BA:33E3E46:6A543808
html-safe-nonce865818166abb342b3c78bffbfcc7fa20508b863ce145c3c94a7bc7322f513e23
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQzRFOjI1RjNFNzoyNjFBM0JBOjMzRTNFNDY6NkE1NDM4MDgiLCJ2aXNpdG9yX2lkIjoiMzU0MzYxNTY3OTA1MDgyMzY4OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmace91a8a5111da6057c5b0ebbe380f671a18fc138c5a0318825c17ebb48ee962b3
hovercard-subject-tagpull_request:3882471119
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/python/cpython/pull/151595/files
twitter:imagehttps://avatars.githubusercontent.com/u/15888476?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/15888476?s=400&v=4
og:image:altFixes #149146. while True: b = (b, None) under RLIMIT_AS segfaults during cleanup: b = 9 while True: b = (b, None) Docker with ulimit -v 524288: MemoryError → lost sys.stderr → segfault, exit 1...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Noneb9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb
turbo-cache-controlno-preview
diff-viewunified
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 full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release07a982c1d40157c619b364352b704c3ce66bb332
ui-targetcanary-2
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/pull/151595/files#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F151595%2Ffiles
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
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
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://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
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F151595%2Ffiles
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/pull/151595/files
Reloadhttps://github.com/python/cpython/pull/151595/files
Reloadhttps://github.com/python/cpython/pull/151595/files
Please reload this pagehttps://github.com/python/cpython/pull/151595/files
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/pull/151595/files
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 35k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 73.8k https://github.com/login?return_to=%2Fpython%2Fcpython
Code https://github.com/python/cpython
Issues 5k+ https://github.com/python/cpython/issues
Pull requests 2.3k https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security and quality 0 https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
Code https://github.com/python/cpython
Issues https://github.com/python/cpython/issues
Pull requests https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security and quality https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
Sign up for GitHub https://github.com/signup?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
bhuvi27https://github.com/bhuvi27
python:mainhttps://github.com/python/cpython/tree/main
bhuvi27:gh-149146-tuple-memoryerror-cleanuphttps://github.com/bhuvi27/cpython/tree/gh-149146-tuple-memoryerror-cleanup
Conversation 6 https://github.com/python/cpython/pull/151595
Commits 1 https://github.com/python/cpython/pull/151595/commits
Checks 56 https://github.com/python/cpython/pull/151595/checks
Files changed https://github.com/python/cpython/pull/151595/files
Please reload this pagehttps://github.com/python/cpython/pull/151595/files
gh-149146: Add dealloc-depth counter fallback to trashcan trigger https://github.com/python/cpython/pull/151595/files#top
Show all changes 1 commit https://github.com/python/cpython/pull/151595/files
5562097 gh-149146: Add dealloc-depth counter fallback to trashcan trigger bhuvi27 Jun 17, 2026 https://github.com/python/cpython/pull/151595/commits/55620976d3ef5a67cee1ae5a8e7310f64b80ce1b
Clear filters https://github.com/python/cpython/pull/151595/files
Please reload this pagehttps://github.com/python/cpython/pull/151595/files
Please reload this pagehttps://github.com/python/cpython/pull/151595/files
pystate.h https://github.com/python/cpython/pull/151595/files#diff-fefbbf791abe2a1b6d9cab39778d388ebb9135eeefbd734e463aac75d1979e7f
test_gc.py https://github.com/python/cpython/pull/151595/files#diff-9d9e863bd2a456b669ec9600be793699e861340d91d7c417a8a5b5b8cfbd09a7
2026-06-17-15-55-00.gh-issue-149146.Tr8aLk.rst https://github.com/python/cpython/pull/151595/files#diff-e768bd91a9a8c8f70be6fab198fb4b17da9d094dc78b25a92ba5dbb0aafb1cd4
object.c https://github.com/python/cpython/pull/151595/files#diff-ba56d44ce0dd731d979970b966fde9d8dd15d12a82f727a052a8ad48d4a49363
pystate.c https://github.com/python/cpython/pull/151595/files#diff-7ac11e526f79b42d6ea9d3592cb99da46775640c69fa5510f4a6de87cced7141
https://github.com/python/cpython/blob/main/.github/CODEOWNERS#L321
Include/cpython/pystate.hhttps://github.com/python/cpython/pull/151595/files#diff-fefbbf791abe2a1b6d9cab39778d388ebb9135eeefbd734e463aac75d1979e7f
View file https://github.com/bhuvi27/cpython/blob/55620976d3ef5a67cee1ae5a8e7310f64b80ce1b/Include/cpython/pystate.h
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/151595/{{ revealButtonHref }}
https://github.com/python/cpython/pull/151595/files#diff-fefbbf791abe2a1b6d9cab39778d388ebb9135eeefbd734e463aac75d1979e7f
https://github.com/python/cpython/pull/151595/files#diff-fefbbf791abe2a1b6d9cab39778d388ebb9135eeefbd734e463aac75d1979e7f
Lib/test/test_gc.pyhttps://github.com/python/cpython/pull/151595/files#diff-9d9e863bd2a456b669ec9600be793699e861340d91d7c417a8a5b5b8cfbd09a7
View file https://github.com/bhuvi27/cpython/blob/55620976d3ef5a67cee1ae5a8e7310f64b80ce1b/Lib/test/test_gc.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/151595/{{ revealButtonHref }}
https://github.com/python/cpython/pull/151595/files#diff-9d9e863bd2a456b669ec9600be793699e861340d91d7c417a8a5b5b8cfbd09a7
https://github.com/python/cpython/pull/151595/files#diff-9d9e863bd2a456b669ec9600be793699e861340d91d7c417a8a5b5b8cfbd09a7
Misc/NEWS.d/next/Core_and_Builtins/2026-06-17-15-55-00.gh-issue-149146.Tr8aLk.rsthttps://github.com/python/cpython/pull/151595/files#diff-e768bd91a9a8c8f70be6fab198fb4b17da9d094dc78b25a92ba5dbb0aafb1cd4
View file https://github.com/bhuvi27/cpython/blob/55620976d3ef5a67cee1ae5a8e7310f64b80ce1b/Misc/NEWS.d/next/Core_and_Builtins/2026-06-17-15-55-00.gh-issue-149146.Tr8aLk.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/151595/{{ revealButtonHref }}
https://github.com/python/cpython/blob/main/.github/CODEOWNERS#L218
Objects/object.chttps://github.com/python/cpython/pull/151595/files#diff-ba56d44ce0dd731d979970b966fde9d8dd15d12a82f727a052a8ad48d4a49363
View file https://github.com/bhuvi27/cpython/blob/55620976d3ef5a67cee1ae5a8e7310f64b80ce1b/Objects/object.c
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/151595/{{ revealButtonHref }}
https://github.com/python/cpython/pull/151595/files#diff-ba56d44ce0dd731d979970b966fde9d8dd15d12a82f727a052a8ad48d4a49363
https://github.com/python/cpython/pull/151595/files#diff-ba56d44ce0dd731d979970b966fde9d8dd15d12a82f727a052a8ad48d4a49363
https://github.com/python/cpython/pull/151595/files#diff-ba56d44ce0dd731d979970b966fde9d8dd15d12a82f727a052a8ad48d4a49363
https://github.com/python/cpython/pull/151595/files#diff-ba56d44ce0dd731d979970b966fde9d8dd15d12a82f727a052a8ad48d4a49363
https://github.com/python/cpython/pull/151595/files#diff-ba56d44ce0dd731d979970b966fde9d8dd15d12a82f727a052a8ad48d4a49363
https://github.com/python/cpython/pull/151595/files#diff-ba56d44ce0dd731d979970b966fde9d8dd15d12a82f727a052a8ad48d4a49363
https://github.com/python/cpython/pull/151595/files#diff-ba56d44ce0dd731d979970b966fde9d8dd15d12a82f727a052a8ad48d4a49363
https://github.com/python/cpython/pull/151595/files#diff-ba56d44ce0dd731d979970b966fde9d8dd15d12a82f727a052a8ad48d4a49363
https://github.com/python/cpython/blob/main/.github/CODEOWNERS#L321
Python/pystate.chttps://github.com/python/cpython/pull/151595/files#diff-7ac11e526f79b42d6ea9d3592cb99da46775640c69fa5510f4a6de87cced7141
View file https://github.com/bhuvi27/cpython/blob/55620976d3ef5a67cee1ae5a8e7310f64b80ce1b/Python/pystate.c
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/151595/{{ revealButtonHref }}
https://github.com/python/cpython/pull/151595/files#diff-7ac11e526f79b42d6ea9d3592cb99da46775640c69fa5510f4a6de87cced7141
https://github.com/python/cpython/pull/151595/files#diff-7ac11e526f79b42d6ea9d3592cb99da46775640c69fa5510f4a6de87cced7141
Please reload this pagehttps://github.com/python/cpython/pull/151595/files
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.