Skip to content

gh-159091: Fix a data race in PyFunction_GetAnnotations() - #159094

Open
hetaozdh wants to merge 1 commit into
python:mainfrom
hetaozdh:gh-159091-pyfunction-getannotations
Open

hetaozdh wants to merge 1 commit into
python:mainfrom
hetaozdh:gh-159091-pyfunction-getannotations

Conversation

@hetaozdh

@hetaozdh hetaozdh commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Fixes gh-159091.

The Python-level getter mentioned in issue is already protected by a critical section generated by Argument Clinic. The missing lock is in PyFunction_GetAnnotations(), which accesses and may replace func_annotations without holding the function object's critical section.

This adds the lock to the C API and a free-threading test that races C API reads against __annotations__ assignments. The race is only reliably detected in a TSAN build.

Add a critical section to `PyFunction_GetAnnotations()` to prevent data races in free-threaded builds.
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.

func_get_annotation_dict missing critical section after gh-128714

1 participant