René's URL Explorer Experiment


Title: gh-151424: Fix impossible stack traces in `RemoteUnwinder(..., cache_frames=True)` by copying chunks on cache miss by maurycy · Pull Request #151426 · python/cpython · GitHub

Open Graph Title: gh-151424: Fix impossible stack traces in `RemoteUnwinder(..., cache_frames=True)` by copying chunks on cache miss by maurycy · Pull Request #151426 · python/cpython

X Title: gh-151424: Fix impossible stack traces in `RemoteUnwinder(..., cache_frames=True)` by copying chunks on cache miss by maurycy · Pull Request #151426 · python/cpython

Description: The issue is caused by memory walks with cache_frames=True when there's a cache miss. If I understand the whole machniery correctly. Basically, we don't copy chunks in cache mode: cpython/Modules/_remote_debugging/threads.c Lines 506 to 512 in f4f1020 // In cache mode, copying stack chunks is more expensive than direct memory reads if (!unwinder->cache_frames) { if (copy_stack_chunks(unwinder, *current_tstate, &chunks) < 0) { set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to copy stack chunks"); goto error; } } So there are never any chunks in the cache mode, not a problem with full cache hits: cpython/Modules/_remote_debugging/frames.c Lines 328 to 351 in f4f1020 if (ctx->chunks && ctx->chunks->count > 0) { if (parse_frame_from_chunks(unwinder, &frame, frame_addr, &next_frame_addr, &stackpointer, ctx->chunks) == 0) { goto parsed_frame; } PyErr_Clear(); } { uintptr_t address_of_code_object = 0; int parse_result; if (ctx->prefetch.frame && ctx->prefetch.frame_addr == frame_addr) { parse_result = parse_frame_buffer( unwinder, &frame, ctx->prefetch.frame, &address_of_code_object, &next_frame_addr); } else { parse_result = parse_frame_object( unwinder, &frame, frame_addr, &address_of_code_object, &next_frame_addr); } if (parse_result < 0) { set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to parse frame object in chain"); return -1; } } But when there's no cache hit: cpython/Modules/_remote_debugging/frames.c Lines 578 to 585 in f4f1020 int full_hit = try_full_cache_hit(unwinder, ctx, thread_id); if (full_hit != 0) { return full_hit < 0 ? -1 : 0; } Py_ssize_t frames_before = PyList_GET_SIZE(ctx->frame_info); if (process_frame_chain(unwinder, ctx) < 0) { it falls back to many memory reads: cpython/Modules/_remote_debugging/frames.c Line 315 in f4f1020 while ((void*)frame_addr != NULL) { cpython/Modules/_remote_debugging/frames.c Lines 236 to 242 in f4f1020 char frame[SIZEOF_INTERP_FRAME]; Py_ssize_t bytes_read = _Py_RemoteDebug_ReadRemoteMemory( &unwinder->handle, address, SIZEOF_INTERP_FRAME, frame ); which isn't very atomic... the target mutates between reads and we're lost. That's definitely the cause. Is there a cleaner fix ? One side-note - let's not tighten the validation yet? Generally, it's a statistical profiler so we should have some statistical tests for correctness, too. Proof Reusing def leaf_a(): return sum(range(50)) def leaf_b(): return sum(range(50)) def hot_a(): return leaf_a() def hot_b(): return leaf_b() while True: hot_a(); hot_b(); from #151424 we get 2026-06-13T03:14:37.706845000+0200 maurycy@gimel /Users/maurycy/src/github.com/maurycy/cpython (gh-151424 141f623*?) % sudo ./python.exe -m profiling.sampling run --collapsed -o /tmp/stacks.txt -d 10 repro.py Captured 10,000 samples in 10.00 seconds Sample rate: 999.99 samples/sec Error rate: 14.91 Collapsed stack output written to /tmp/stacks.txt 2026-06-13T03:14:51.568490000+0200 maurycy@gimel /Users/maurycy/src/github.com/maurycy/cpython (gh-151424 141f623*?) % cat /tmp/stacks.txt tid:13199240;:_run_module_as_main:201;:_run_code:87;repro.py::6;repro.py:hot_a:3;repro.py:leaf_a:1 3324 tid:13199240;:_run_module_as_main:201;:_run_code:87;repro.py::6;repro.py:hot_b:4;repro.py:leaf_b:2 3269 tid:13199240;:_run_module_as_main:201;:_run_code:87;repro.py::6 1234 tid:13199240;:_run_module_as_main:201;:_run_code:87;repro.py::6;repro.py:hot_a:3 341 tid:13199240;:_run_module_as_main:201;:_run_code:87;repro.py::6;repro.py:hot_b:4 324 tid:13199240;:_run_module_as_main:201;:_run_code:87;repro.py::6;repro.py:hot_b:4;repro.py:leaf_b:-1 8 tid:13199240;:_run_module_as_main:201;:_run_code:87;repro.py::6;repro.py:hot_a:3;repro.py:leaf_a:-1 6 tid:13199240;:_run_module_as_main:201;:_run_code:87;repro.py::6;repro.py:hot_a:3;repro.py:leaf_b:2 1 tid:13199240;:_run_module_as_main:201;:_run_code:87;repro.py::6;repro.py:leaf_a:1 1 tid:13199240;:_run_module_as_main:201;:_run_code:87;repro.py::6;repro.py:leaf_b:2 1 2026-06-13T03:15:14.324823000+0200 maurycy@gimel /Users/maurycy/src/github.com/maurycy/cpython (gh-151424 141f623*?) % The impossible rate went to just 0,20%. Issue: gh-151424

Open Graph Description: The issue is caused by memory walks with cache_frames=True when there's a cache miss. If I understand the whole machniery correctly. Basically, we don't copy chunks in cache mode: ...

X Description: The issue is caused by memory walks with cache_frames=True when there&#39;s a cache miss. If I understand the whole machniery correctly. Basically, we don&#39;t copy chunks in cache mode: ...

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

X: @github

direct link

Domain: github.com

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/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:c0de6545-620e-e696-1738-516004b4a6c7
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idD1C4:AFBD9:22F887E:2DDD8AC:6B024BAD
html-safe-noncee2ba4c2f70be8f9080c4a47337b1d58ed1dd22f7434726e3c09e755c1c03c465
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMUM0OkFGQkQ5OjIyRjg4N0U6MkRERDhBQzo2QjAyNEJBRCIsInZpc2l0b3JfaWQiOiI2MDg1Mjg0MDMzODUwMzk1NTY1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac84b60d8b93684672445637714301ec01d6a7a0a0b3a3435e6a91830ce64c4cc9
hovercard-subject-tagpull_request:3858518128
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/151426/files
twitter:imagehttps://avatars.githubusercontent.com/u/5383?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/5383?s=400&v=4
og:image:altThe issue is caused by memory walks with cache_frames=True when there's a cache miss. If I understand the whole machniery correctly. Basically, we don't copy chunks in cache mode: ...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
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
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/pull/151426/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F151426%2Ffiles
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%2Fpull%2F151426%2Ffiles
Sign uphttps://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/151426/files
Reloadhttps://github.com/python/cpython/pull/151426/files
Reloadhttps://github.com/python/cpython/pull/151426/files
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
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
pablogsalhttps://github.com/pablogsal
python:mainhttps://github.com/python/cpython/tree/main
maurycy:gh-151424https://github.com/maurycy/cpython/tree/gh-151424
Conversation 3 https://github.com/python/cpython/pull/151426
Commits 3 https://github.com/python/cpython/pull/151426/commits
Checks 62 https://github.com/python/cpython/pull/151426/checks
Files changed https://github.com/python/cpython/pull/151426/files
Please reload this pagehttps://github.com/python/cpython/pull/151426/files
gh-151424: Fix impossible stack traces in RemoteUnwinder(..., cache_frames=True) by copying chunks on cache miss https://github.com/python/cpython/pull/151426/files#top
Show all changes 3 commits https://github.com/python/cpython/pull/151426/files
141f623 sync chunks? maurycy Jun 13, 2026 https://github.com/python/cpython/pull/151426/commits/141f623669b2c9fb239f2d28933ba3da38736947
8b7f97d news maurycy Jun 13, 2026 https://github.com/python/cpython/pull/151426/commits/8b7f97d86a3363c919afccda6bf4c8e14933f6cc
39564f8 better news maurycy Jun 13, 2026 https://github.com/python/cpython/pull/151426/commits/39564f8adb5cd0145a9bd2417d2f2deb32643267
Clear filters https://github.com/python/cpython/pull/151426/files
Please reload this pagehttps://github.com/python/cpython/pull/151426/files
Please reload this pagehttps://github.com/python/cpython/pull/151426/files
2026-06-13-04-11-00.gh-issue-151426.f2V67e.rst https://github.com/python/cpython/pull/151426/files#diff-f4503d78f832c5bdcf001a52223064cb7d4f140f5978dfc0001b8a3171b47e0c
frames.c https://github.com/python/cpython/pull/151426/files#diff-7d46b926220bc5035fbce1ec940bb27482bcd7683fdcbc1f60b1fd2bb9bf6f41
Misc/NEWS.d/next/Library/2026-06-13-04-11-00.gh-issue-151426.f2V67e.rsthttps://github.com/python/cpython/pull/151426/files#diff-f4503d78f832c5bdcf001a52223064cb7d4f140f5978dfc0001b8a3171b47e0c
View file https://github.com/maurycy/cpython/blob/39564f8adb5cd0145a9bd2417d2f2deb32643267/Misc/NEWS.d/next/Library/2026-06-13-04-11-00.gh-issue-151426.f2V67e.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/151426/{{ revealButtonHref }}
https://github.com/python/cpython/blob/main/.github/CODEOWNERS#L336
Modules/_remote_debugging/frames.chttps://github.com/python/cpython/pull/151426/files#diff-7d46b926220bc5035fbce1ec940bb27482bcd7683fdcbc1f60b1fd2bb9bf6f41
View file https://github.com/maurycy/cpython/blob/39564f8adb5cd0145a9bd2417d2f2deb32643267/Modules/_remote_debugging/frames.c
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/151426/{{ revealButtonHref }}
https://github.com/python/cpython/pull/151426/files#diff-7d46b926220bc5035fbce1ec940bb27482bcd7683fdcbc1f60b1fd2bb9bf6f41
https://github.com/python/cpython/pull/151426/files#diff-7d46b926220bc5035fbce1ec940bb27482bcd7683fdcbc1f60b1fd2bb9bf6f41
Please reload this pagehttps://github.com/python/cpython/pull/151426/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.