Title: Data race in `sys_set_flag` when `sys.set_int_max_str_digits()` is called concurrently with free-threaded build · Issue #151218 · python/cpython · GitHub
Open Graph Title: Data race in `sys_set_flag` when `sys.set_int_max_str_digits()` is called concurrently with free-threaded build · Issue #151218 · python/cpython
X Title: Data race in `sys_set_flag` when `sys.set_int_max_str_digits()` is called concurrently with free-threaded build · Issue #151218 · python/cpython
Description: Bug report Bug description: sys.set_int_max_str_digits() updates sys.flags via sys_set_flag(), which modifies a shared struct-sequence slot without synchronization: cpython/Python/sysmodule.c Lines 3479 to 3487 in ce916dc static void sys...
Open Graph Description: Bug report Bug description: sys.set_int_max_str_digits() updates sys.flags via sys_set_flag(), which modifies a shared struct-sequence slot without synchronization: cpython/Python/sysmodule.c Lines...
X Description: Bug report Bug description: sys.set_int_max_str_digits() updates sys.flags via sys_set_flag(), which modifies a shared struct-sequence slot without synchronization: cpython/Python/sysmodule.c Lines...
Opengraph URL: https://github.com/python/cpython/issues/151218
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Data race in `sys_set_flag` when `sys.set_int_max_str_digits()` is called concurrently with free-threaded build","articleBody":"# Bug report\n\n### Bug description:\n\n`sys.set_int_max_str_digits()` updates `sys.flags` via `sys_set_flag()`, which modifies a shared struct-sequence slot without synchronization:\n\nhttps://github.com/python/cpython/blob/ce916dc50644bb1de940f5fb580bd9907cceb959/Python/sysmodule.c#L3479-L3487\n\nConcurrent callers race on the slot and can `Py_XDECREF` the same `old_value`, leading to a use-after-free of the old flag object.\n\nReproducer:\n```python\nimport sys\nfrom threading import Thread\n\ndef thread1():\n for i in range (20000):\n sys.set_int_max_str_digits(4300 + (i \u0026 7))\n\nthreads = [Thread(target=thread1) for _ in range(4)]\nfor t in threads: t.start()\nfor t in threads: t.join()\n```\n\nTSAN Report:\n```\n==================\nWARNING: ThreadSanitizer: data race (pid=1518581)\n Read of size 8 at 0x7fffb63e01b8 by thread T1:\n #0 PyStructSequence_GetItem /cpython/Objects/structseq.c:112:12 \n #1 sys_set_flag /cpython/./Python/sysmodule.c:3484:27 \n #2 _PySys_SetFlagObj /cpython/./Python/sysmodule.c:3498:5 \n #3 _PySys_SetFlagInt /cpython/./Python/sysmodule.c:3512:15 \n #4 _PySys_SetIntMaxStrDigits /cpython/./Python/sysmodule.c:4671:9 \n #5 sys_set_int_max_str_digits_impl /cpython/./Python/sysmodule.c:1894:9 \n #6 sys_set_int_max_str_digits /cpython/./Python/clinic/sysmodule.c.h:932:20 \n #7 _Py_BuiltinCallFastWithKeywords_StackRef /cpython/Python/ceval.c:839:11 \n #8 _PyEval_EvalFrameDefault /cpython/Python/generated_cases.c.h:2508:35 \n\n Previous write of size 8 at 0x7fffb63e01b8 by thread T2:\n #0 PyStructSequence_SetItem /cpython/Objects/structseq.c:100:27 \n #1 sys_set_flag /cpython/./Python/sysmodule.c:3485:5 \n #2 _PySys_SetFlagObj /cpython/./Python/sysmodule.c:3498:5 \n #3 _PySys_SetFlagInt /cpython/./Python/sysmodule.c:3512:15 \n #4 _PySys_SetIntMaxStrDigits /cpython/./Python/sysmodule.c:4671:9 \n #5 sys_set_int_max_str_digits_impl /cpython/./Python/sysmodule.c:1894:9 \n #6 sys_set_int_max_str_digits /cpython/./Python/clinic/sysmodule.c.h:932:20 \n #7 cfunction_vectorcall_FASTCALL_KEYWORDS /cpython/Objects/methodobject.c:465:24 \n #8 _PyObject_VectorcallTstate /cpython/./Include/internal/pycore_call.h:144:11 \n #9 PyObject_Vectorcall /cpython/Objects/call.c:327:12\n...\nSUMMARY: ThreadSanitizer: data race /cpython/Objects/structseq.c:112:12 in PyStructSequence_GetItem\n==================\n==================\nWARNING: ThreadSanitizer: data race (pid=1518581)\n Read of size 4 at 0x7fffc004057c by thread T2:\n #0 _Py_ExplicitMergeRefcount /cpython/Objects/object.c:477:40 \n #1 _Py_brc_queue_object /cpython/Python/brc.c:73:31 \n #2 _Py_DecRefSharedIsDead /cpython/Objects/object.c:413:9 \n #3 _Py_DecRefSharedDebug /cpython/Objects/object.c:425:9 \n #4 _Py_DecRefShared /cpython/Objects/object.c:433:5 \n #5 Py_DECREF /cpython/./Include/refcount.h:385:9 \n #6 Py_XDECREF /cpython/./Include/refcount.h:520:9 \n #7 sys_set_flag /cpython/./Python/sysmodule.c:3486:5 \n #8 _PySys_SetFlagObj /cpython/./Python/sysmodule.c:3498:5 \n #9 _PySys_SetFlagInt /cpython/./Python/sysmodule.c:3512:15 \n #10 _PySys_SetIntMaxStrDigits /cpython/./Python/sysmodule.c:4671:9 \n #11 sys_set_int_max_str_digits_impl /cpython/./Python/sysmodule.c:1894:9 \n #12 sys_set_int_max_str_digits /cpython/./Python/clinic/sysmodule.c.h:932:20 \n\n Previous atomic write of size 4 at 0x7fffc004057c by thread T3:\n #0 _Py_atomic_store_uint32_relaxed /cpython/./Include/cpython/pyatomic_gcc.h:493:3 \n #1 Py_DECREF /cpython/./Include/refcount.h:379:9 \n #2 Py_XDECREF /cpython/./Include/refcount.h:520:9 \n #3 sys_set_flag /cpython/./Python/sysmodule.c:3486:5 \n #4 _PySys_SetFlagObj /cpython/./Python/sysmodule.c:3498:5 \n #5 _PySys_SetFlagInt /cpython/./Python/sysmodule.c:3512:15 \n #6 _PySys_SetIntMaxStrDigits /cpython/./Python/sysmodule.c:4671:9 \n #7 sys_set_int_max_str_digits_impl /cpython/./Python/sysmodule.c:1894:9 \n #8 sys_set_int_max_str_digits /cpython/./Python/clinic/sysmodule.c.h:932:20 \n...\nSUMMARY: ThreadSanitizer: data race /cpython/Objects/object.c:477:40 in _Py_ExplicitMergeRefcount\n==================\n==================\nWARNING: ThreadSanitizer: data race (pid=1518581)\n Read of size 8 at 0x7fffc4042720 by thread T3:\n #0 long_dealloc /cpython/Objects/longobject.c:3653:9 \n #1 _Py_Dealloc /cpython/Objects/object.c:3312:5 \n #2 _Py_brc_queue_object /cpython/Python/brc.c \n #3 _Py_DecRefSharedIsDead /cpython/Objects/object.c:413:9 \n #4 _Py_DecRefSharedDebug /cpython/Objects/object.c:425:9 \n #5 _Py_DecRefShared /cpython/Objects/object.c:433:5 \n #6 Py_DECREF /cpython/./Include/refcount.h:385:9 \n #7 Py_XDECREF /cpython/./Include/refcount.h:520:9 \n #8 sys_set_flag /cpython/./Python/sysmodule.c:3486:5 \n #9 _PySys_SetFlagObj /cpython/./Python/sysmodule.c:3498:5 \n #10 _PySys_SetFlagInt /cpython/./Python/sysmodule.c:3512:15 \n #11 _PySys_SetIntMaxStrDigits /cpython/./Python/sysmodule.c:4671:9 \n #12 sys_set_int_max_str_digits_impl /cpython/./Python/sysmodule.c:1894:9 \n #13 sys_set_int_max_str_digits /cpython/./Python/clinic/sysmodule.c.h:932:20 \n\n Previous write of size 8 at 0x7fffc4042720 by thread T4:\n #0 _PyLong_SetSignAndDigitCount /cpython/./Include/internal/pycore_long.h:307:27 \n #1 _PyLong_FromMedium /cpython/Objects/longobject.c:267:5 \n #2 PyLong_FromLong /cpython/Objects/longobject.c:409:5 \n #3 _PySys_SetFlagInt /cpython/./Python/sysmodule.c:3507:21 \n #4 _PySys_SetIntMaxStrDigits /cpython/./Python/sysmodule.c:4671:9 \n #5 sys_set_int_max_str_digits_impl /cpython/./Python/sysmodule.c:1894:9 \n #6 sys_set_int_max_str_digits /cpython/./Python/clinic/sysmodule.c.h:932:20 \n...\nSUMMARY: ThreadSanitizer: data race /cpython/Objects/longobject.c:3653:9 in long_dealloc\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 --\u003e\n### Linked PRs\n* gh-151220\n* gh-151402\n* gh-151552\n* gh-151553\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/Naserume","@type":"Person","name":"Naserume"},"datePublished":"2026-06-10T03:58:54.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/151218/cpython/issues/151218"}
| 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:5ff878f6-6894-d726-1878-0b1922404066 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8468:1ABF46:7D55F:AF1B5:6A59BC11 |
| html-safe-nonce | ce881ca281dbf038f8d7e7ac8a6631ccc0dec20aea1aebfe04e406e5dfea7d2c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NDY4OjFBQkY0Njo3RDU1RjpBRjFCNTo2QTU5QkMxMSIsInZpc2l0b3JfaWQiOiIyMjczMTY1NDM5NTIxMTExMDU4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 6566ebc920d0252c0f39e92c627ec101665263192ff73c59628c9898424c9918 |
| hovercard-subject-tag | issue:4627822440 |
| 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/151218/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1461a648e7a7c2698438015a17900e4d376d6f393f684e6d7fab57e331bc566a/python/cpython/issues/151218 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1461a648e7a7c2698438015a17900e4d376d6f393f684e6d7fab57e331bc566a/python/cpython/issues/151218 |
| og:image:alt | Bug report Bug description: sys.set_int_max_str_digits() updates sys.flags via sys_set_flag(), which modifies a shared struct-sequence slot without synchronization: cpython/Python/sysmodule.c Lines... |
| 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 | ba3976babb66479b1c943a8edc0777d96157da48fadc0161f9ddb219deee8353 |
| 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 | ab680789ae4a316cdaf0d5a292a1760140931cc4 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width