Skip to content

gh-151218: Fix data race in sys_set_flag for free-threading#151220

Open
bhuvi27 wants to merge 1 commit into
python:mainfrom
bhuvi27:gh-151218-fix-sys-set-flag-race
Open

gh-151218: Fix data race in sys_set_flag for free-threading#151220
bhuvi27 wants to merge 1 commit into
python:mainfrom
bhuvi27:gh-151218-fix-sys-set-flag-race

Conversation

@bhuvi27

@bhuvi27 bhuvi27 commented Jun 10, 2026

Copy link
Copy Markdown

Fixes #151218

Concurrent calls to sys.set_int_max_str_digits() in free-threaded builds
could double-free the same sys.flags tuple item because sys_set_flag()
updated the slot without synchronization.

Protect sys.flags updates with a mutex in free-threaded builds, and hold
the same lock across flag and interpreter int_max_str_digits state updates
so sys.get_int_max_str_digits() stays consistent with sys.flags. Add a
concurrent stress regression test in test_sys.py.

Concurrent calls to sys.set_int_max_str_digits() in free-threaded builds
could double-free the same sys.flags tuple item because sys_set_flag()
updated the slot without synchronization.

Protect sys.flags updates with a mutex in free-threaded builds and hold
the same lock across the flag and interpreter int_max_str_digits state
updates so sys.get_int_max_str_digits() stays consistent with sys.flags.
@bhuvi27 bhuvi27 force-pushed the gh-151218-fix-sys-set-flag-race branch from 099518a to 09f17c8 Compare June 10, 2026 06:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Data race in sys_set_flag when sys.set_int_max_str_digits() is called concurrently with free-threaded build

1 participant