-
Notifications
You must be signed in to change notification settings - Fork 726
Fix race condition in DropInTokio
#4593
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
The previous code had a race condition - it was possible that `Arc::get_mut` would return `None` for all threads (if every thread holding a cloned `DropInTokio` executed `drop` simultaneously). This would cause the inner `Client` to not get dropped within the 'in_tokio_runtime_no_gil', leading to a panic when the inner drop tried to use the Tokio runtime
|
I'm not sure if this is related to #4326 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a critical race condition in the DropInTokio implementation where multiple threads dropping cloned instances simultaneously could cause Arc::get_mut to return None for all threads, preventing proper cleanup of the inner Client within the Tokio runtime.
Key changes:
- Replaced
Arc::get_mutwithArc::into_innerto guarantee exactly one thread succeeds in extracting the inner value - Modified the dummy value to be wrapped in an
Arcto work with the newstd::mem::replaceapproach
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
#4595 will make this unnecessary, since the relevant logic is entirely removed in that PR |
|
I'm going to merge #4595 instead |
The previous code had a race condition - it was possible that
Arc::get_mutwould returnNonefor all threads (if every thread holding a clonedDropInTokioexecuteddropsimultaneously). This would cause the innerClientto not get dropped within the 'in_tokio_runtime_no_gil', leading to a panic when the inner drop tried to use the Tokio runtimeImportant
Fixes race condition in
DropInTokio::dropby usingArc::into_innerto ensure proper dropping of innerClient.DropInTokio::dropby usingArc::into_innerinstead ofArc::get_mutto ensure proper dropping of innerClientwithinin_tokio_runtime_no_gil.DropInTokiosimultaneously.Arc::get_mutwithArc::into_innerinDropInTokio::dropingil_helpers.rs.This description was created by
for e8e625c. You can customize this summary. It will automatically update as commits are pushed.