Fix PyFileDescriptor creation data race under free-threading - #29697
Draft
copybara-service[bot] wants to merge 1 commit into
Draft
Fix PyFileDescriptor creation data race under free-threading#29697copybara-service[bot] wants to merge 1 commit into
copybara-service[bot] wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix PyFileDescriptor creation data race under free-threading
Under Python 3.14 free-threading (PYTHON_GIL=0), concurrent accesses to
descriptor.fileon un-cached descriptors race duringPyFileDescriptor_FromDescriptorWithSerializedPbinitialization, asGetOrInsertpublishes the descriptor to the cache beforeserialized_pbis set by the calling thread.
This CL fixes the data race by extracting
NewInternedDescriptorWithInitwhich accepts an initialization callback that runs safely before the
newly created object is published to the
PyWeakValueMapcache.