Title: Data race with Context ctx_vars under free-threading · Issue #155519 · python/cpython · GitHub
Open Graph Title: Data race with Context ctx_vars under free-threading · Issue #155519 · python/cpython
X Title: Data race with Context ctx_vars under free-threading · Issue #155519 · python/cpython
Description: Bug report Bug description: The HAMT held by a context is immutable, but the pointer to it is not: contextvar_set() and contextvar_del() install a new HAMT and drop the reference to the previous one. Only the thread that entered a contex...
Open Graph Description: Bug report Bug description: The HAMT held by a context is immutable, but the pointer to it is not: contextvar_set() and contextvar_del() install a new HAMT and drop the reference to the previous on...
X Description: Bug report Bug description: The HAMT held by a context is immutable, but the pointer to it is not: contextvar_set() and contextvar_del() install a new HAMT and drop the reference to the previous on...
Opengraph URL: https://github.com/python/cpython/issues/155519
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Data race with Context ctx_vars under free-threading","articleBody":"# Bug report\n\n### Bug description:\n\nThe HAMT held by a context is immutable, but the pointer to it is not: `contextvar_set()` and `contextvar_del()` install a new HAMT and drop the reference to the previous one. Only the thread that entered a context can do that (a context cannot be entered by two threads at once), but any thread can read a context object at any time -- `ctx.copy()`, `len(ctx)`, `ctx.items()`, etc. Such a reader has to acquire its own reference to the HAMT under the context's lock; reading `ctx_vars` unlocked lets the writer deallocate the HAMT while the reader is walking it.\n\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nLinux\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-155522\n* gh-155892\n* gh-155893\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/nascheme","@type":"Person","name":"nascheme"},"datePublished":"2026-08-10T20:25:29Z","url":"https://github.com/python/cpython/issues/155519"}
| 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:91ec2e08-3399-34b1-b885-8b98a93ecc09 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9276:D1D28:1DF08F8:2796979:6B0231C0 |
| html-safe-nonce | 7da2df674cf94ef56510ebf4f0b90298b2d25208e4c5542e547e99357741087c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5Mjc2OkQxRDI4OjFERjA4Rjg6Mjc5Njk3OTo2QjAyMzFDMCIsInZpc2l0b3JfaWQiOiIxNDMyNjcwMjcxMzMyMDM3MDU2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 53a73cc15f87e3024a1de95b79cb2dd7145300a4292c1476ac2409b42d398b85 |
| hovercard-subject-tag | issue:5114059510 |
| 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/155519/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ed602886c6ca5b5abbd5372ca3003cad274b962ef738843ffa832c4026ac65d2/python/cpython/issues/155519 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ed602886c6ca5b5abbd5372ca3003cad274b962ef738843ffa832c4026ac65d2/python/cpython/issues/155519 |
| og:image:alt | Bug report Bug description: The HAMT held by a context is immutable, but the pointer to it is not: contextvar_set() and contextvar_del() install a new HAMT and drop the reference to the previous on... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | nascheme |
| 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 | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width