Title: Data race creating `types.GenericAlias.__parameters__` lazily under free-threading · Issue #153298 · python/cpython · GitHub
Open Graph Title: Data race creating `types.GenericAlias.__parameters__` lazily under free-threading · Issue #153298 · python/cpython
X Title: Data race creating `types.GenericAlias.__parameters__` lazily under free-threading · Issue #153298 · python/cpython
Description: Bug report Bug description: In the free-threaded build, reading __parameters__ on a shared types.GenericAlias (e.g. list[T]) from multiple threads races on the lazy creation of the cached parameters tuple. ga_parameters checks and fills ...
Open Graph Description: Bug report Bug description: In the free-threaded build, reading __parameters__ on a shared types.GenericAlias (e.g. list[T]) from multiple threads races on the lazy creation of the cached parameter...
X Description: Bug report Bug description: In the free-threaded build, reading __parameters__ on a shared types.GenericAlias (e.g. list[T]) from multiple threads races on the lazy creation of the cached parameter...
Opengraph URL: https://github.com/python/cpython/issues/153298
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Data race creating `types.GenericAlias.__parameters__` lazily under free-threading","articleBody":"# Bug report\n\n### Bug description:\n\nIn the free-threaded build, reading `__parameters__` on a shared `types.GenericAlias` (e.g. `list[T]`) from multiple threads races on the lazy creation of the cached `parameters` tuple. \n`ga_parameters` checks and fills `alias->parameters` with plain accesses.\n\nhttps://github.com/python/cpython/blob/a74280e6696125acb7628facc577d0f975c4d69e/Objects/genericaliasobject.c#L843-L853\n\nTwo threads that both observe `parameters == NULL` both compute and store the tuple, racing on the cache pointer.\n\nReproducer:\n```python\nfrom threading import Thread\nfrom typing import TypeVar\n\nT = TypeVar('T')\nslot = [list[T]]\n\ndef thread1():\n for _ in range(20000):\n try:\n _ = slot[0].__parameters__\n except Exception:\n pass\n\ndef thread2():\n for _ in range(20000):\n slot[0] = list[T] # fresh GenericAlias (parameters == NULL)\n\nthreads = [Thread(target=thread1) for _ in range(6)]\nthreads += [Thread(target=thread2) for _ in range(2)]\nfor t in threads: t.start()\nfor t in threads: t.join()\n```\n\nTSAN Report:\n```\n==================\nWARNING: ThreadSanitizer: data race (pid=48591)\n Write of size 8 at 0x7fffd00d0580 by thread T4:\n #0 ga_parameters /cpython/Objects/genericaliasobject.c:848:27 \n #1 getset_get /cpython/Objects/descrobject.c:194:16 \n #2 _PyObject_GenericGetAttrWithDict /cpython/Objects/object.c:1926:19 \n #3 PyObject_GenericGetAttr /cpython/Objects/object.c:2012:12 \n #4 ga_getattro /cpython/Objects/genericaliasobject.c:708:12 \n #5 _PyObject_GetAttrStackRef /cpython/Objects/object.c:1369:18 \n #6 _PyEval_EvalFrameDefault /cpython/Python/generated_cases.c.h:8786:28 \n...\n\n Previous read of size 8 at 0x7fffd00d0580 by thread T3:\n #0 ga_parameters /cpython/Objects/genericaliasobject.c:847:16 \n #1 getset_get /cpython/Objects/descrobject.c:194:16 \n #2 _PyObject_GenericGetAttrWithDict /cpython/Objects/object.c:1926:19 \n #3 PyObject_GenericGetAttr /cpython/Objects/object.c:2012:12 \n #4 ga_getattro /cpython/Objects/genericaliasobject.c:708:12 \n #5 _PyObject_GetAttrStackRef /cpython/Objects/object.c:1369:18 \n #6 _PyEval_EvalFrameDefault /cpython/Python/generated_cases.c.h:8786:28 \n...\n\nSUMMARY: ThreadSanitizer: data race /cpython/Objects/genericaliasobject.c:848:27 in ga_parameters\n==================\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-153318\n* gh-153345\n* gh-153346\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/Naserume","@type":"Person","name":"Naserume"},"datePublished":"2026-07-07T21:51:29Z","url":"https://github.com/python/cpython/issues/153298"}
| 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:b94a95d7-974e-b9b9-fcd9-a5fe99277897 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AEEA:1087D4:368C84E:48DA71C:6B0214A7 |
| html-safe-nonce | c98d17321ffeef22fd13deb40b84c2f09acd898eccc95b0fe88fcc0028de29aa |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRUVBOjEwODdENDozNjhDODRFOjQ4REE3MUM6NkIwMjE0QTciLCJ2aXNpdG9yX2lkIjoiMTU1MjA0ODE2NTc2OTg0Mzg3OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | a89793e17f6b00794ac4717a0accb6da904645abf32426a9108bae841861f4f1 |
| hovercard-subject-tag | issue:4832500494 |
| 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/153298/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3b01bbadc87798c76dbdfb609c082abd60767521cc256a4267ad6515cbe74ca6/python/cpython/issues/153298 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3b01bbadc87798c76dbdfb609c082abd60767521cc256a4267ad6515cbe74ca6/python/cpython/issues/153298 |
| og:image:alt | Bug report Bug description: In the free-threaded build, reading __parameters__ on a shared types.GenericAlias (e.g. list[T]) from multiple threads races on the lazy creation of the cached parameter... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Naserume |
| 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