Title: Free-threaded GC can abort during concurrent subinterpreter teardown · Issue #161751 · python/cpython · GitHub
Open Graph Title: Free-threaded GC can abort during concurrent subinterpreter teardown · Issue #161751 · python/cpython
X Title: Free-threaded GC can abort during concurrent subinterpreter teardown · Issue #161751 · python/cpython
Description: Crash report OpTree CI hit this assertion on an unmodified Windows x64 free-threaded debug build of CPython 3.14.10 (b703b2c). An InterpreterPoolExecutor worker was destroying its interpreter. The native stack went from Py_EndInterpreter...
Open Graph Description: Crash report OpTree CI hit this assertion on an unmodified Windows x64 free-threaded debug build of CPython 3.14.10 (b703b2c). An InterpreterPoolExecutor worker was destroying its interpreter. The ...
X Description: Crash report OpTree CI hit this assertion on an unmodified Windows x64 free-threaded debug build of CPython 3.14.10 (b703b2c). An InterpreterPoolExecutor worker was destroying its interpreter. The ...
Opengraph URL: https://github.com/python/cpython/issues/161751
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Free-threaded GC can abort during concurrent subinterpreter teardown","articleBody":"### Crash report\n\n[OpTree](https://github.com/metaopt/optree/) CI hit this assertion on an unmodified Windows x64 free-threaded debug build of CPython 3.14.10 (`b703b2c`). An `InterpreterPoolExecutor` worker was destroying its interpreter. The native stack went from `Py_EndInterpreter()` through shutdown GC to `mi_abandoned_visit_blocks()` and `validate_alive_bits()`.\n\nCI backtrace: https://github.com/metaopt/optree/actions/runs/42811376193/job/129813367183#step:18:1\n\n```text\nPython/gc_free_threading.c:1082: validate_alive_bits:\nAssertion \"!gc_is_alive(op)\" failed: object should not be marked as alive yet\n```\n\nI suspect a race in the abandoned-segment scan introduced with the mimalloc 2.5.2 update. One interpreter can temporarily clear a segment’s bitmap bit, discover that the segment belongs to another interpreter, and restore the bit. The owning interpreter’s GC reads the bitmap **before** acquiring `abandoned_visit_lock`. If it reads during that interval, it can skip the segment. The same scan is present on `main` at `9d4a35c`.\n\nAllocator code: https://github.com/python/cpython/blob/v3.14.10/Objects/mimalloc/arena-abandon.c#L209-L269\n\n- 3.14 backport: #160183\n\n---\n\n### Standard Library Reproducer\n\nStarting from `v3.14.10`, add `usleep(100);` inside the foreign-segment branch of `mi_arena_segment_clear_abandoned_at()`, immediately before it restores the bitmap bit.\n\n```diff\n if (segment->subproc != subproc) {\n+ usleep(100);\n // it is from another sub-process, re-mark it and continue searching\n```\n\nBuild with `./configure --with-pydebug --disable-gil` and `make`. Save this as `repro.py` and run `./python.exe -I -X dev repro.py` on macOS.\n\n```python\nfrom concurrent import interpreters\nfrom concurrent.futures import ThreadPoolExecutor\nfrom threading import Barrier\n\nworkers = 8\nbarrier = Barrier(workers)\n\n\ndef run(_worker_id):\n for _ in range(10):\n interp = interpreters.create()\n barrier.wait()\n interp.exec('import gc\\ngc.collect()')\n interp.close()\n\n\nwith ThreadPoolExecutor(workers) as pool:\n list(pool.map(run, range(workers)))\n```\n\nWith the timing change, this reduced case aborted in `validate_gc_objects()` on all three runs. A longer standard-library stress test also reproduced the exact `validate_alive_bits()` assertion from Windows. On stock macOS debug builds, that longer test completed 340 rounds each on 3.14.9 and 3.14.10.\n\nAs a control, I kept the delay and moved lock acquisition ahead of the first bitmap read for full scans (`previous->visit_all`). The longer workload then completed a 10-round run. The precise thread interleaving in the original Windows crash is unknown.\n\n### CPython versions tested on:\n\n3.14\n\n### Operating systems tested on:\n\nmacOS\n\n### Output from running 'python -VV' on the command line:\n\n_No response_\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-162003\n* gh-162269\n* gh-162270\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/XuehaiPan","@type":"Person","name":"XuehaiPan"},"datePublished":"2026-11-10T15:59:52Z","url":"https://github.com/python/cpython/issues/161751"}
| 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:47bc7b18-c892-4a4d-269e-c7fc36fee851 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B880:317608:3DC7811:4E3066F:6B0207C9 |
| html-safe-nonce | f88c5553d28251475a55c98f83aab36c897908447e3331d20e5790c3f27ace10 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCODgwOjMxNzYwODozREM3ODExOjRFMzA2NkY6NkIwMjA3QzkiLCJ2aXNpdG9yX2lkIjoiMTA5OTAyMjIzOTUyMjc1MjQ1NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | d0b2210fc8d85e925824f47df9514c88451093f82ef024b54399d4795cd50a47 |
| hovercard-subject-tag | issue:6310602307 |
| 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/161751/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3780e4b1cbb2d52f4789d5fdc6896fe1a7b61fda253b2010ac3ef10e15e09b8e/python/cpython/issues/161751 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3780e4b1cbb2d52f4789d5fdc6896fe1a7b61fda253b2010ac3ef10e15e09b8e/python/cpython/issues/161751 |
| og:image:alt | Crash report OpTree CI hit this assertion on an unmodified Windows x64 free-threaded debug build of CPython 3.14.10 (b703b2c). An InterpreterPoolExecutor worker was destroying its interpreter. The ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | XuehaiPan |
| 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