René's URL Explorer Experiment


Title: `_remote_debugging`: `RemoteUnwinder` caches the interpreters list head in `__init__` as the main interpreter · Issue #159262 · python/cpython · GitHub

Open Graph Title: `_remote_debugging`: `RemoteUnwinder` caches the interpreters list head in `__init__` as the main interpreter · Issue #159262 · python/cpython

X Title: `_remote_debugging`: `RemoteUnwinder` caches the interpreters list head in `__init__` as the main interpreter · Issue #159262 · python/cpython

Description: Bug report An existing RemoteUnwinder misses interpreters created after its constructor runs. If the saved interpreter closes, later samples can read freed memory. The default mode also selects the main thread of the newest interpreter a...

Open Graph Description: Bug report An existing RemoteUnwinder misses interpreters created after its constructor runs. If the saved interpreter closes, later samples can read freed memory. The default mode also selects the...

X Description: Bug report An existing RemoteUnwinder misses interpreters created after its constructor runs. If the saved interpreter closes, later samples can read freed memory. The default mode also selects the...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`_remote_debugging`: `RemoteUnwinder` caches the interpreters list head in `__init__` as the main interpreter","articleBody":"### Bug report\n\n\nAn existing `RemoteUnwinder` misses interpreters created after its constructor runs. If the saved interpreter closes, later samples can read freed memory. The default mode also selects the main thread of the newest interpreter and can omit the main interpreter.\n\nFound while reviewing #158900, #158971 and working on #159259.\n\n## Reproductions\n\n### A new interpreter is missing from an existing unwinder\n\nThe existing unwinder returns only interpreter `0`. A new unwinder sees both interpreters:\n\n```python\nimport os\nfrom concurrent import interpreters\nfrom _remote_debugging import RemoteUnwinder\n\nunwinder = RemoteUnwinder(os.getpid(), all_threads=True)\ninterp = interpreters.create()\ntry:\n    print([i.interpreter_id for i in unwinder.get_stack_trace()])\n    fresh = RemoteUnwinder(os.getpid(), all_threads=True)\n    print([i.interpreter_id for i in fresh.get_stack_trace()])\nfinally:\n    interp.close()\n```\n\n```bash\n2026-10-12T22:43:31.492120000+0200 maurycy@gimel /Users/maurycy/work/cpython (main 5e049c3) % ./python.exe /tmp/aaa.py\n[0]\n[1, 0]\n```\n\n### The saved interpreter closes\n\n```bash\nmaurycy@gimel cpython (main 9028df3) % cat /tmp/repro_dangling.py\nimport os\nfrom concurrent import interpreters\nfrom _remote_debugging import RemoteUnwinder\n\ninterp = interpreters.create()\nunwinder = RemoteUnwinder(os.getpid(), all_threads=True)\ninterp.close()\nprint([i.interpreter_id for i in unwinder.get_stack_trace()])\nmaurycy@gimel cpython (main 9028df3) % ./python.exe /tmp/repro_dangling.py\nTraceback (most recent call last):\n  File \"/tmp/repro_dangling.py\", line 8, in \u003cmodule>\n    print([i.interpreter_id for i in unwinder.get_stack_trace()])\n                                     ~~~~~~~~~~~~~~~~~~~~~~~~^^\nRuntimeError: mach_vm_read_overwrite failed for PID 32948 at address 0xdddddddddddddddd (size 888): kern_return_t 1\n```\n\n`0xdd` is the debug allocator's dead byte (with `PYTHONMALLOC=debug`)\n\n### The default mode omits the main interpreter\n\n```python\nfrom concurrent import interpreters\n\ninterp = interpreters.create()\ntry:\n    interp.exec(\"\"\"\nimport os\nfrom _remote_debugging import RemoteUnwinder\nfor all_threads in (False, True):\n    unwinder = RemoteUnwinder(os.getpid(), all_threads=all_threads)\n    unwinder.get_stack_trace()\n    print(all_threads, [i.interpreter_id for i in unwinder.get_stack_trace()])\n\"\"\")\nfinally:\n    interp.close()\n```\n\n```bash\n2026-10-12T22:54:47.076383000+0200 maurycy@gimel /Users/maurycy/work/cpython (main 5e049c3) % ./python.exe /tmp/xoxo.py\nFalse [1]\nTrue [1, 0]\n```\n\n\u003cdetails>\n\u003csummary>Additional cases: an idle interpreter and a freed thread state\u003c/summary>\n\nIdle subinterpreter (main interpreter has two threads):\n\n```bash\n2026-10-12T22:54:49.923205000+0200 maurycy@gimel /Users/maurycy/work/cpython (main 5e049c3) % cat /tmp/repro_idle_default.py\nimport os, threading, time\nfrom concurrent import interpreters\nfrom _remote_debugging import RemoteUnwinder\n\nev = threading.Event()\nt = threading.Thread(target=ev.wait); t.start()\ninterp = interpreters.create()\nfor kwargs in ({}, {\"all_threads\": True}):\n    u = RemoteUnwinder(os.getpid(), **kwargs); u.get_stack_trace()\n    print(kwargs, [(i.interpreter_id, len(i.threads)) for i in u.get_stack_trace()])\nev.set(); t.join(); interp.close()\n2026-10-12T22:55:14.833746000+0200 maurycy@gimel /Users/maurycy/work/cpython (main 5e049c3) % ./python.exe /tmp/repro_idle_default.py\n{} [(1, 0), (0, 2)]\n{'all_threads': True} [(1, 0), (0, 2)]\n```\n\nThe subinterpreter goes idle after `__init__`, releasing the saved thread state. The sample still omits the main interpreter:\n\n```bash\nmaurycy@gimel cpython (main 9028df3) % cat /tmp/repro_stale_tstate.py\nimport os, threading, time\nfrom concurrent import interpreters\nfrom _remote_debugging import RemoteUnwinder\n\ninterp = interpreters.create()\nt = threading.Thread(target=interp.exec, args=(\"import time; time.sleep(0.5)\",)); t.start(); time.sleep(0.2)\nunwinder = RemoteUnwinder(os.getpid())\nt.join()\nprint([(i.interpreter_id, [f.funcname for t in i.threads for f in t.frame_info]) for i in unwinder.get_stack_trace()])\ninterp.close()\nmaurycy@gimel cpython (main 9028df3) % ./python.exe /tmp/repro_stale_tstate.py\n[(1, [])]\n```\n\n\u003c/details>\n\n## Cause\n\nThe constructor saves `runtime->interpreters.head` as `self->interpreter_addr`.\n\nWith `all_threads=False`, it also saves `head->threads_main` as `self->tstate_addr`:\n\nhttps://github.com/python/cpython/blob/9028df36bb9e2942b19164f6708f9cf8a55c5ce9/Modules/_remote_debugging/module.c#L422-L423\nhttps://github.com/python/cpython/blob/9028df36bb9e2942b19164f6708f9cf8a55c5ce9/Modules/_remote_debugging/threads.c#L92-L128\n\nWhere:\n\n- New interpreters are prepended. A saved head can omit new entries or point to freed memory.\n- The head provides the thread to sample. It is the newest interpreter, and `get_stack_trace()` stops after it when the saved thread address is non-zero.\n\nhttps://github.com/python/cpython/blob/9028df36bb9e2942b19164f6708f9cf8a55c5ce9/Python/pystate.c#L740\nhttps://github.com/python/cpython/blob/9028df36bb9e2942b19164f6708f9cf8a55c5ce9/Python/pystate.c#L1050-L1066\nhttps://github.com/python/cpython/blob/9028df36bb9e2942b19164f6708f9cf8a55c5ce9/Modules/_remote_debugging/module.c#L887-L890\n\nAn idle subinterpreter has `threads_main == NULL`. That sets `tstate_addr` to zero, which seems to select all threads. A running subinterpreter can also release its saved main thread state after `exec()` returns:\n\nhttps://github.com/python/cpython/blob/9028df36bb9e2942b19164f6708f9cf8a55c5ce9/Python/crossinterp.c#L2621\n\nTwo questions:\n\n- The CLI docs say \"only the main thread\". The method docstring says \"the main thread of each interpreter\". Sampling each interpreter's main thread would follow the method docstring.\n- Some embedders may not set `threads.main`. The proposed selection returns no default-mode threads for those interpreters, instead of accidentally returning all threads.\n\nhttps://github.com/python/cpython/blob/9028df36bb9e2942b19164f6708f9cf8a55c5ce9/Modules/_remote_debugging/module.c#L670-L674\nhttps://github.com/python/cpython/blob/9028df36bb9e2942b19164f6708f9cf8a55c5ce9/Doc/library/profiling.sampling.rst#L477\nhttps://github.com/python/cpython/blob/9028df36bb9e2942b19164f6708f9cf8a55c5ce9/Python/pystate.c#L1164-L1170\n\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nmacOS","author":{"url":"https://github.com/maurycy","@type":"Person","name":"maurycy"},"datePublished":"2026-10-12T21:03:08Z","url":"https://github.com/python/cpython/issues/159262"}

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:8f0813a0-330b-04f4-3506-7d27794b2ba8
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id9D78:A71F9:3A656CF:49D6F0F:6B0232E7
html-safe-nonce7aa57e2147d9da580c0ae0f647a36d83add0955c47ec3ed67294d93eb8a0f2bd
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RDc4OkE3MUY5OjNBNjU2Q0Y6NDlENkYwRjo2QjAyMzJFNyIsInZpc2l0b3JfaWQiOiI4MDc5ODgzMjkxNTQyNTY1NjA3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac9defcf42b0c8d3c2b43577c65ac00e839f63a1cdcc5a882b4bff266bdb3a9cd3
hovercard-subject-tagissue:5820391401
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/159262/issue_layout
twitter:imagehttps://opengraph.githubassets.com/50c576b7b5654a585f098ba5460ef28b293d3af3094cb666d2be7b66364e96f9/python/cpython/issues/159262
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/50c576b7b5654a585f098ba5460ef28b293d3af3094cb666d2be7b66364e96f9/python/cpython/issues/159262
og:image:altBug report An existing RemoteUnwinder misses interpreters created after its constructor runs. If the saved interpreter closes, later samples can read freed memory. The default mode also selects the...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamemaurycy
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/159262#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F159262
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%2F159262
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/159262
Reloadhttps://github.com/python/cpython/issues/159262
Reloadhttps://github.com/python/cpython/issues/159262
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/159262
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/159262
_remote_debugging: RemoteUnwinder caches the interpreters list head in __init__ as the main interpreterhttps://github.com/python/cpython/issues/159262#top
extension-modulesC modules in the Modules dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22extension-modules%22
topic-profilinghttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-profiling%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com/maurycy
maurycyhttps://github.com/maurycy
on Oct 12, 2026https://github.com/python/cpython/issues/159262#issue-5820391401
#158900https://github.com/python/cpython/pull/158900
#158971https://github.com/python/cpython/pull/158971
#159259https://github.com/python/cpython/pull/159259
cpython/Modules/_remote_debugging/module.chttps://github.com/python/cpython/blob/9028df36bb9e2942b19164f6708f9cf8a55c5ce9/Modules/_remote_debugging/module.c#L422-L423
9028df3https://github.com/python/cpython/commit/9028df36bb9e2942b19164f6708f9cf8a55c5ce9
cpython/Modules/_remote_debugging/threads.chttps://github.com/python/cpython/blob/9028df36bb9e2942b19164f6708f9cf8a55c5ce9/Modules/_remote_debugging/threads.c#L92-L128
9028df3https://github.com/python/cpython/commit/9028df36bb9e2942b19164f6708f9cf8a55c5ce9
cpython/Python/pystate.chttps://github.com/python/cpython/blob/9028df36bb9e2942b19164f6708f9cf8a55c5ce9/Python/pystate.c#L740
9028df3https://github.com/python/cpython/commit/9028df36bb9e2942b19164f6708f9cf8a55c5ce9
cpython/Python/pystate.chttps://github.com/python/cpython/blob/9028df36bb9e2942b19164f6708f9cf8a55c5ce9/Python/pystate.c#L1050-L1066
9028df3https://github.com/python/cpython/commit/9028df36bb9e2942b19164f6708f9cf8a55c5ce9
cpython/Modules/_remote_debugging/module.chttps://github.com/python/cpython/blob/9028df36bb9e2942b19164f6708f9cf8a55c5ce9/Modules/_remote_debugging/module.c#L887-L890
9028df3https://github.com/python/cpython/commit/9028df36bb9e2942b19164f6708f9cf8a55c5ce9
cpython/Python/crossinterp.chttps://github.com/python/cpython/blob/9028df36bb9e2942b19164f6708f9cf8a55c5ce9/Python/crossinterp.c#L2621
9028df3https://github.com/python/cpython/commit/9028df36bb9e2942b19164f6708f9cf8a55c5ce9
cpython/Modules/_remote_debugging/module.chttps://github.com/python/cpython/blob/9028df36bb9e2942b19164f6708f9cf8a55c5ce9/Modules/_remote_debugging/module.c#L670-L674
9028df3https://github.com/python/cpython/commit/9028df36bb9e2942b19164f6708f9cf8a55c5ce9
cpython/Doc/library/profiling.sampling.rsthttps://github.com/python/cpython/blob/9028df36bb9e2942b19164f6708f9cf8a55c5ce9/Doc/library/profiling.sampling.rst#L477
9028df3https://github.com/python/cpython/commit/9028df36bb9e2942b19164f6708f9cf8a55c5ce9
cpython/Python/pystate.chttps://github.com/python/cpython/blob/9028df36bb9e2942b19164f6708f9cf8a55c5ce9/Python/pystate.c#L1164-L1170
9028df3https://github.com/python/cpython/commit/9028df36bb9e2942b19164f6708f9cf8a55c5ce9
maurycyhttps://github.com/maurycy
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
on Oct 12, 2026https://github.com/python/cpython/issues/159262#event-33080757245
https://github.com/maurycy
maurycyhttps://github.com/maurycy
on Oct 12, 2026https://github.com/python/cpython/issues/159262#issuecomment-6132586149
@pablogsalhttps://github.com/pablogsal
picnixzhttps://github.com/picnixz
extension-modulesC modules in the Modules dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22extension-modules%22
topic-profilinghttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-profiling%22
on Oct 13, 2026https://github.com/python/cpython/issues/159262#event-33092503517
kevinprimeraquecreo-stackhttps://github.com/kevinprimeraquecreo-stack
Project_VKhttps://github.com/users/kevinprimeraquecreo-stack/projects/1
on Oct 18, 2026https://github.com/python/cpython/issues/159262#event-33592163680
github-project-automationhttps://github.com/apps/github-project-automation
Project_VKhttps://github.com/users/kevinprimeraquecreo-stack/projects/1
on Oct 18, 2026https://github.com/python/cpython/issues/159262
kevinprimeraquecreo-stackhttps://github.com/kevinprimeraquecreo-stack
Project_VKhttps://github.com/users/kevinprimeraquecreo-stack/projects/1
on Oct 18, 2026https://github.com/python/cpython/issues/159262#event-33592179908
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/159262
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/159262
extension-modulesC modules in the Modules dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22extension-modules%22
topic-profilinghttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-profiling%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.