Title: Data race in `intern_common` when interning str objects in the free threading build · Issue #129701 · python/cpython · GitHub
Open Graph Title: Data race in `intern_common` when interning str objects in the free threading build · Issue #129701 · python/cpython
X Title: Data race in `intern_common` when interning str objects in the free threading build · Issue #129701 · python/cpython
Description: Bug report When running ./python -m test test_exceptions --parallel-threads=10 in a TSAN build: WARNING: ThreadSanitizer: data race (pid=763025) Atomic read of size 4 at 0x7fffbe0718cc by thread T190: #0 _Py_atomic_load_uint32_relaxed In...
Open Graph Description: Bug report When running ./python -m test test_exceptions --parallel-threads=10 in a TSAN build: WARNING: ThreadSanitizer: data race (pid=763025) Atomic read of size 4 at 0x7fffbe0718cc by thread T1...
X Description: Bug report When running ./python -m test test_exceptions --parallel-threads=10 in a TSAN build: WARNING: ThreadSanitizer: data race (pid=763025) Atomic read of size 4 at 0x7fffbe0718cc by thread T1...
Opengraph URL: https://github.com/python/cpython/issues/129701
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Data race in `intern_common` when interning str objects in the free threading build","articleBody":"# Bug report\n\nWhen running `./python -m test test_exceptions --parallel-threads=10` in a TSAN build:\n\n```\nWARNING: ThreadSanitizer: data race (pid=763025)\n Atomic read of size 4 at 0x7fffbe0718cc by thread T190:\n #0 _Py_atomic_load_uint32_relaxed Include/cpython/pyatomic_gcc.h:367 (python+0x1d386e) (BuildId: 5612db6eff0f51c7fd99ee4409b2ceafceea484c)\n #1 Py_INCREF Include/refcount.h:261 (python+0x1d386e)\n #2 _Py_NewRef Include/refcount.h:518 (python+0x1d386e)\n #3 dict_setdefault_ref_lock_held Objects/dictobject.c:4386 (python+0x1e6817) (BuildId: 5612db6eff0f51c7fd99ee4409b2ceafceea484c)\n #4 PyDict_SetDefaultRef Objects/dictobject.c:4403 (python+0x1e6a37) (BuildId: 5612db6eff0f51c7fd99ee4409b2ceafceea484c)\n #5 intern_common Objects/unicodeobject.c:15820 (python+0x2a7a8d) (BuildId: 5612db6eff0f51c7fd99ee4409b2ceafceea484c)\n #6 _PyUnicode_InternImmortal Objects/unicodeobject.c:15874 (python+0x2e92d1) (BuildId: 5612db6eff0f51c7fd99ee4409b2ceafceea484c)\n #7 _PyPegen_new_identifier Parser/pegen.c:549 (python+0xad61f) (BuildId: 5612db6eff0f51c7fd99ee4409b2ceafceea484c)\n....\n\n Previous write of size 4 at 0x7fffbe0718cc by thread T182:\n #0 Py_SET_REFCNT Include/refcount.h:176 (python+0x2a7c9a) (BuildId: 5612db6eff0f51c7fd99ee4409b2ceafceea484c)\n #1 Py_SET_REFCNT Include/refcount.h:145 (python+0x2a7c9a)\n #2 intern_common Objects/unicodeobject.c:15848 (python+0x2a7c9a)\n #3 _PyUnicode_InternImmortal Objects/unicodeobject.c:15874 (python+0x2e92d1) (BuildId: 5612db6eff0f51c7fd99ee4409b2ceafceea484c)\n #4 _PyPegen_new_identifier Parser/pegen.c:549 (python+0xad61f) (BuildId: 5612db6eff0f51c7fd99ee4409b2ceafceea484c)\n...\n```\n\nThere are a few thread-safety issues with `intern_common`:\n\n* It can return a string that's not marked as interned because we insert into `interned` before we mark the string as interned. This can be fixed with some additional locking.\n* The `Py_SET_REFCNT(s, Py_REFCNT(s) - 2)` modification is not thread-safe with respect to other reference count modifications in the free threading build\n* `_Py_SetImmortal` is not thread-safe in some circumstances (see https://github.com/python/cpython/issues/113956)\n\nThe `_Py_SetImmortal()` issue is tricky and I think it's unlikely to cause problems in practice, so I think we can defer dealing with that for now.\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-130089\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/colesbury","@type":"Person","name":"colesbury"},"datePublished":"2025-02-05T20:42:11.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":8},"url":"https://github.com/129701/cpython/issues/129701"}
| 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:c984de73-784f-4c57-0d00-a9d38ba23f66 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B100:12A9AF:43A67:550A0:696AFB97 |
| html-safe-nonce | 8c9279f8116519bfcd466a5413f7124e2e882b44f1427475987fa395516516f5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMTAwOjEyQTlBRjo0M0E2Nzo1NTBBMDo2OTZBRkI5NyIsInZpc2l0b3JfaWQiOiI5MDQ0MzM2Mjc1MzUwMDI3MTU5IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 64a5308959e3391a79d52d78abee071cb2209779334539a1ad811a663e5de209 |
| hovercard-subject-tag | issue:2833922439 |
| 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/129701/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a6d1e78448e026103396b327831e809f05fb4d1c3b33fc7949d92975338d04af/python/cpython/issues/129701 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a6d1e78448e026103396b327831e809f05fb4d1c3b33fc7949d92975338d04af/python/cpython/issues/129701 |
| og:image:alt | Bug report When running ./python -m test test_exceptions --parallel-threads=10 in a TSAN build: WARNING: ThreadSanitizer: data race (pid=763025) Atomic read of size 4 at 0x7fffbe0718cc by thread T1... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | colesbury |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5f99f7c1d70f01da5b93e5ca90303359738944d8ab470e396496262c66e60b8d |
| 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 | 82560a55c6b2054555076f46e683151ee28a19bc |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width