Skip to content

Fix PyFileDescriptor creation data race under free-threading - #29697

Draft
copybara-service[bot] wants to merge 1 commit into
mainfrom
test_979094955
Draft

Fix PyFileDescriptor creation data race under free-threading#29697
copybara-service[bot] wants to merge 1 commit into
mainfrom
test_979094955

Conversation

@copybara-service

Copy link
Copy Markdown

Fix PyFileDescriptor creation data race under free-threading

Under Python 3.14 free-threading (PYTHON_GIL=0), concurrent accesses to
descriptor.file on un-cached descriptors race during
PyFileDescriptor_FromDescriptorWithSerializedPb initialization, as
GetOrInsert publishes the descriptor to the cache before serialized_pb
is set by the calling thread.

This CL fixes the data race by extracting NewInternedDescriptorWithInit
which accepts an initialization callback that runs safely before the
newly created object is published to the PyWeakValueMap cache.

Under Python 3.14 free-threading (PYTHON_GIL=0), concurrent accesses to
`descriptor.file` on un-cached descriptors race during
`PyFileDescriptor_FromDescriptorWithSerializedPb` initialization, as
`GetOrInsert` publishes the descriptor to the cache before `serialized_pb`
is set by the calling thread.

This CL fixes the data race by extracting `NewInternedDescriptorWithInit`
which accepts an initialization callback that runs safely before the
newly created object is published to the `PyWeakValueMap` cache.

PiperOrigin-RevId: 979094955
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant