Title: Crash in HAMT during garbage collection · Issue #148891 · python/cpython · GitHub
Open Graph Title: Crash in HAMT during garbage collection · Issue #148891 · python/cpython
X Title: Crash in HAMT during garbage collection · Issue #148891 · python/cpython
Description: Crash report What happened? We discovered a crash in the https://github.com/datadog/dd-trace-py library we maintain that actually seems to be rooted in CPython, not our own code. Error UnixSignal: Process terminated with SEGV_MAPERR (SIG...
Open Graph Description: Crash report What happened? We discovered a crash in the https://github.com/datadog/dd-trace-py library we maintain that actually seems to be rooted in CPython, not our own code. Error UnixSignal: ...
X Description: Crash report What happened? We discovered a crash in the https://github.com/datadog/dd-trace-py library we maintain that actually seems to be rooted in CPython, not our own code. Error UnixSignal: ...
Opengraph URL: https://github.com/python/cpython/issues/148891
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Crash in HAMT during garbage collection","articleBody":"# Crash report\n\n### What happened?\n\nWe discovered a crash in the https://github.com/datadog/dd-trace-py library we maintain that actually seems to be rooted in CPython, not our own code.\n\n```\nError UnixSignal: Process terminated with SEGV_MAPERR (SIGSEGV)\n#0 0x00007fc92c3dd27f PyObject_GC_UnTrack\n#1 0x00007fc92c4e1448 PyContextVar_Set\n#2 0x00007fc92c3f3546 _PyEval_EvalFrameDefault\n#3 0x00007fc92c3fbce7 PyObject_Vectorcall\n#4 0x00007fc92c3f039b _PyEval_EvalFrameDefault\n#5 0x00007fc92c3f2f38 _PyEval_EvalFrameDefault\n#6 0x00007fc92c3f2f38 _PyEval_EvalFrameDefault\n#7 0x00007fc92c3f2f38 _PyEval_EvalFrameDefault\n#8 0x00007fc92c3f2f38 _PyEval_EvalFrameDefault\n#9 0x00007fc92c44e25f PyIter_Send\n#10 0x00007fc92c3f2f38 _PyEval_EvalFrameDefault\n#11 0x00007fc92c3f2f38 _PyEval_EvalFrameDefault\n#12 0x00007fc92c3f2f38 _PyEval_EvalFrameDefault\n#13 0x00007fc92c3f2f38 _PyEval_EvalFrameDefault\n#14 0x00007fc92c3f2f38 _PyEval_EvalFrameDefault\n#15 0x00007fc92c3f2f38 _PyEval_EvalFrameDefault\n#16 0x00007fc92c3f2f38 _PyEval_EvalFrameDefault\n#17 0x00007fc92c3f2f38 _PyEval_EvalFrameDefault\n#18 0x00007fc92c3f2f38 _PyEval_EvalFrameDefault\n#19 0x00007fc92c3f2f38 _PyEval_EvalFrameDefault\n#20 0x00007fc92c3f2f38 _PyEval_EvalFrameDefault\n#21 0x00007fc92c3f2f38 _PyEval_EvalFrameDefault\n#22 0x00007fc92c3f2f38 _PyEval_EvalFrameDefault\n#23 0x00007fc92c3f2f38 _PyEval_EvalFrameDefault\n#24 0x00007fc92c3f2f38 _PyEval_EvalFrameDefault\n#25 0x00007fc92c3f2f38 _PyEval_EvalFrameDefault\n#26 0x00007fc92c3f2f38 _PyEval_EvalFrameDefault\n#27 0x00007fc92c3f2f38 _PyEval_EvalFrameDefault\n#28 0x00007fc92c3f2f38 _PyEval_EvalFrameDefault\n#29 0x00007fc92c3f2f38 _PyEval_EvalFrameDefault\n#30 0x00007fc92c3f2f38 _PyEval_EvalFrameDefault\n#31 0x00007fc92c3f2f38 _PyEval_EvalFrameDefault\n#32 0x00007fc92c3f2f38 _PyEval_EvalFrameDefault\n#33 0x00007fc92c3f2f38 _PyEval_EvalFrameDefault\n#34 0x00007fc8f1f854ff __Pyx_PyObject_Call (/project/uvloop/loop.c:191431:15)\n#35 0x00007fc8f204f948 __pyx_f_6uvloop_4loop_6Handle__run (/project/uvloop/loop.c:66901:25)\n#36 0x00007fc8f2053f7c __pyx_f_6uvloop_4loop_4Loop__on_idle (/project/uvloop/loop.c:17975:25)\n#37 0x00007fc8f204f9a6 __pyx_f_6uvloop_4loop_6Handle__run (/project/uvloop/loop.c:66927:24)\n#38 0x00007fc8f2051047 __pyx_f_6uvloop_4loop_cb_idle_callback (/project/uvloop/loop.c:87335:19)\n#39 0x00007fc8f20687d1 uv__run_idle (/project/build/libuv-x86_64/src/unix/loop-watcher.c:68:1)\n#40 0x00007fc8f2065b07 uv_run (/project/build/libuv-x86_64/src/unix/core.c:439:5)\n#41 0x00007fc8f1fb83a0 __pyx_f_6uvloop_4loop_4Loop__Loop__run (/project/uvloop/loop.c:18458:23)\n#42 0x00007fc8f1ff612d __pyx_f_6uvloop_4loop_4Loop__run (/project/uvloop/loop.c:18876:18)\n#43 0x00007fc8f1ff1e85 __pyx_pf_6uvloop_4loop_4Loop_24run_forever (/project/uvloop/loop.c:31528:18)\n#44 0x00007fc8f1ff1e85 __pyx_pw_6uvloop_4loop_4Loop_25run_forever (/project/uvloop/loop.c:31331:13)\n#45 0x00007fc92c3ec26e PyObject_VectorcallMethod\n#46 0x00007fc92c3f039b _PyEval_EvalFrameDefault\n#47 0x00007fc92c47474c PyEval_EvalCode\n#48 0x00007fc92c4a24a7 _PyRun_SimpleFileObject\n#49 0x00007fc92c4a1b38 _PyRun_AnyFileObject\n#50 0x00007fc92c49c3be Py_RunMain\n#51 0x00007fc92c46461b Py_BytesMain\n#52 0x00007fc92c067d65 __libc_start_main\n#53 0x0000559068986071 _start\n```\n\nWe fixed the crash on our side with https://github.com/DataDog/dd-trace-py/pull/17407 but figured it might still be worth reporting upstream.\n\nThe crash happens in `PyObject_GC_UnTrack`, called from the dealloc path of a HAMT node that `PyContextVar_Set` is trying to free via `Py_DECREF`. If that HAMT node's memory is already unmapped, the `PyObject_GC_UnTrack` write faults.\n\nWe discovered that crash in `dd-trace-py` accidentally because of the following code:\n1. Store a fresh `{}` dict in the context's HAMT under `self._storage`\n2. Put the `Token` returned by `set()` back into that same dict\n\n```python\ndef __enter__(self) -> \"BaseWrappingContext\":\n token: Token = self._storage.set({}) # 1. create new HAMT entry\n self._storage.get()[\"__dd_wrapping_context_token__\"] = token # 2. store Token in dict\n return self\n```\n\n`Token` objects holds `tok_ctx`, which is a strong reference to the `PyContext` that was active when `set` was called -- i.e. `ts->context`.\n\nI unfortunately don't have a proposed fix yet, but I'm looking into it.\n\n### CPython versions tested on:\n\n~3.12~ \n\nEDIT: this is happening on 3.12 but the stack I originally reported (and most crashes I see) are coming from Python 3.10 and 3.11.\n\n### Operating systems tested on:\n\nLinux\n\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-148928\n* gh-161592\n* gh-161593\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/KowalskiThomas","@type":"Person","name":"KowalskiThomas"},"datePublished":"2026-04-22T20:08:12Z","url":"https://github.com/python/cpython/issues/148891"}
| react-profiling | 0 |
| react-import-map | react,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-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:6ec1aee7-39fc-c3e5-7784-6dbcb31cb588 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D3F4:148EE1:50AADE:65ECAA:6B020374 |
| html-safe-nonce | 909d77372b84c13f45dfa333213d27627c43b92d91d7dc8f3332a23a5ac5cf11 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEM0Y0OjE0OEVFMTo1MEFBREU6NjVFQ0FBOjZCMDIwMzc0IiwidmlzaXRvcl9pZCI6Ijg3OTQ3NTg0MjIwMjMzODE2NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 4fbffc1259333bdfa28348c51d1f2e56c5ae17c08a911b2db4d33e6e21912593 |
| hovercard-subject-tag | issue:4311579136 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/148891/issue_layout |
| twitter:image | https://opengraph.githubassets.com/905c9f9ceb51a55a6b9bd589c3fbd8aa3b2f0cd57863961153b9d38fa5c5855a/python/cpython/issues/148891 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/905c9f9ceb51a55a6b9bd589c3fbd8aa3b2f0cd57863961153b9d38fa5c5855a/python/cpython/issues/148891 |
| og:image:alt | Crash report What happened? We discovered a crash in the https://github.com/datadog/dd-trace-py library we maintain that actually seems to be rooted in CPython, not our own code. Error UnixSignal: ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | KowalskiThomas |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width