Skip to content

gh-159458: Fix free-threading data race in datetime strftime century normalization - #159520

Merged
encukou merged 2 commits into
python:mainfrom
AnnaAr321:patch-3
Oct 16, 2026
Merged

encukou merged 2 commits into
python:mainfrom
AnnaAr321:patch-3

Conversation

@AnnaAr321

@AnnaAr321 AnnaAr321 commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

In Modules/_datetimemodule.c, normalize_century() lazily initializes a function-local static int cache = -1; on the first strftime() call using %Y, %G, %F, or %C. Under free-threaded builds (Py_GIL_DISABLED), concurrent initial calls to strftime() race on reading and writing cache, triggering ThreadSanitizer data race warnings.
Use FT_ATOMIC_LOAD_INT_RELAXED and FT_ATOMIC_STORE_INT_RELAXED to atomically load and store cache in free-threaded builds with zero overhead in default GIL-enabled builds.

@encukou

encukou commented Oct 16, 2026

Copy link
Copy Markdown
Member

Thank you.
AFAIK, this doesn't affect users in practice, so the NEWS blurb isn't really necessary. But since you already wrote it, we can keep it.

@encukou
encukou merged commit ddc647a into python:main Oct 16, 2026
56 checks passed
@encukou encukou added awaiting review needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Oct 16, 2026
@miss-islington-app

Copy link
Copy Markdown

Thanks @AnnaAr321 for the PR, and @encukou for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Thanks @AnnaAr321 for the PR, and @encukou for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Oct 16, 2026

Copy link
Copy Markdown

GH-159536 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Oct 16, 2026
@bedevere-app

bedevere-app Bot commented Oct 16, 2026

Copy link
Copy Markdown

GH-159537 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Oct 16, 2026
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.

2 participants