Title: [Free-threading] `assert(!_Py_IsImmortal(op))` failure when BRC merge queue races with `sys.intern` · Issue #152276 · python/cpython · GitHub
Open Graph Title: [Free-threading] `assert(!_Py_IsImmortal(op))` failure when BRC merge queue races with `sys.intern` · Issue #152276 · python/cpython
X Title: [Free-threading] `assert(!_Py_IsImmortal(op))` failure when BRC merge queue races with `sys.intern` · Issue #152276 · python/cpython
Description: Bug report Bug description: In the free-threaded build, there is a race condition where an object can be queued for Biased Reference Counting (BRC) merging, but become immortal before the queue is processed. This causes a fatal C-level a...
Open Graph Description: Bug report Bug description: In the free-threaded build, there is a race condition where an object can be queued for Biased Reference Counting (BRC) merging, but become immortal before the queue is ...
X Description: Bug report Bug description: In the free-threaded build, there is a race condition where an object can be queued for Biased Reference Counting (BRC) merging, but become immortal before the queue is ...
Opengraph URL: https://github.com/python/cpython/issues/152276
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Free-threading] `assert(!_Py_IsImmortal(op))` failure when BRC merge queue races with `sys.intern`","articleBody":"# Bug report\n\n### Bug description:\n\nIn the free-threaded build, there is a race condition where an object can be queued for Biased Reference Counting (BRC) merging, but become immortal *before* the queue is processed. This causes a fatal C-level assertion failure:\n\n```\nassert.h assertion failed at Objects/object.c:467 in Py_ssize_t _Py_ExplicitMergeRefcount(PyObject *, Py_ssize_t): !_Py_IsImmortal(op)\n\n*** Check failure stack trace: ***\n @ _Py_ExplicitMergeRefcount\n @ merge_queued_objects\n @ _Py_brc_merge_refcounts\n @ _Py_HandlePending\n @ _PyEval_EvalFrameDefault\n```\n\nReproduction. Fails when running under ASAN/TSAN and the free-threading build:\n```python\nimport threading\nimport sys\ndef test_race():\n # 1 million strings will trap Thread A inside map() for milliseconds,\n # giving Thread B plenty of time to queue references to strings that \n # Thread A hasn't interned yet.\n strings = [\"race_string_massive_\" + str(j) for j in range(1000000)]\n \n # Give Thread B a copy of the list.\n shared = list(strings)\n \n def thread_b_func():\n # Thread B clears its list, reducing the shared refcount to 0.\n # Since Thread B is not the owner, they are placed in Thread A's merge queue.\n shared.clear()\n tb = threading.Thread(target=thread_b_func)\n tb.start()\n # Thread A executes entirely in C for milliseconds.\n # Strings are queued by Thread B, AND THEN made immortal by sys.intern!\n list(map(sys.intern, strings))\n tb.join()\nif __name__ == \"__main__\":\n test_race()\n```\n\n### CPython versions tested on:\n\n3.14\n\n### Operating systems tested on:\n\nLinux\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-152277\n* gh-162316\n* gh-162318\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/AnnaAr321","@type":"Person","name":"AnnaAr321"},"datePublished":"2026-06-26T13:21:37Z","url":"https://github.com/python/cpython/issues/152276"}
| 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:8464e364-dafa-e204-b52f-db834c27b3b6 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D864:BB75:15E3D63:1CFBE40:6B020254 |
| html-safe-nonce | b5293e547e11a3ab33b6c9ad9c3147516167a88f37333c3b697f5cff422556c0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEODY0OkJCNzU6MTVFM0Q2MzoxQ0ZCRTQwOjZCMDIwMjU0IiwidmlzaXRvcl9pZCI6IjUxMjkzNDcyMTc1MjI2OTM5NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | fc3fbbaad1eae7f02e00014addce6bdb3c7df2c2e8e60af33e5369aa551de0f0 |
| hovercard-subject-tag | issue:4752315269 |
| 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/152276/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a7521851e269d7a130be66db1489ede3aeef5a231436246c555985e9623f27fc/python/cpython/issues/152276 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a7521851e269d7a130be66db1489ede3aeef5a231436246c555985e9623f27fc/python/cpython/issues/152276 |
| og:image:alt | Bug report Bug description: In the free-threaded build, there is a race condition where an object can be queued for Biased Reference Counting (BRC) merging, but become immortal before the queue is ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | AnnaAr321 |
| 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