Skip to content

[Colocated Python] Fix a deadlock during garbage collection under free threading#38144

Merged
copybara-service[bot] merged 1 commit into
mainfrom
test_924981686
Jun 3, 2026
Merged

[Colocated Python] Fix a deadlock during garbage collection under free threading#38144
copybara-service[bot] merged 1 commit into
mainfrom
test_924981686

Conversation

@copybara-service
Copy link
Copy Markdown

[Colocated Python] Fix a deadlock during garbage collection under free threading

Python garbage collection may get stuck indefinitely when colocated Python objects are used in Python free threading. This is because when _ConsumableRef.__call__ holds a mutex lock, garbage collection can happen and invoke MethodCallerAtBackend.__del__ for the MethodCallerAtBackend that used to own that _ConsumableRef object. This MethodCallerAtBackend.__del__ in turn would call the same _ConsumableRef.__call__ and blocks on the same mutex. This problem can be mitigated by making the mutex reentrant, and this does not affect the logic of _ConsumableRef.__call__.

@copybara-service copybara-service Bot force-pushed the test_924981686 branch 5 times, most recently from 51b1575 to 99738b5 Compare June 3, 2026 02:19
…e threading

Python garbage collection may get stuck indefinitely when colocated Python objects are used in Python free threading. This is because when `_ConsumableRef.__call__` holds a mutex lock, garbage collection can happen and invoke `MethodCallerAtBackend.__del__` for the `MethodCallerAtBackend` that used to own that `_ConsumableRef` object. This `MethodCallerAtBackend.__del__` in turn would call the same `_ConsumableRef.__call__` and blocks on the same mutex. This problem can be mitigated by making the mutex reentrant, and this does not affect the logic of `_ConsumableRef.__call__`.

PiperOrigin-RevId: 925717965
@copybara-service copybara-service Bot merged commit 226d04d into main Jun 3, 2026
@copybara-service copybara-service Bot deleted the test_924981686 branch June 3, 2026 02:32
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