Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Aaron1011
Copy link
Member

@Aaron1011 Aaron1011 commented Nov 13, 2025

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


Important

Fixes race condition in DropInTokio::drop by using Arc::into_inner to ensure proper dropping of inner Client.

  • Behavior:
    • Fixes race condition in DropInTokio::drop by using Arc::into_inner instead of Arc::get_mut to ensure proper dropping of inner Client within in_tokio_runtime_no_gil.
    • Prevents panic when multiple threads drop DropInTokio simultaneously.
  • Code Changes:
    • Replaces Arc::get_mut with Arc::into_inner in DropInTokio::drop in gil_helpers.rs.

This description was created by Ellipsis for e8e625c. You can customize this summary. It will automatically update as commits are pushed.

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
Copilot AI review requested due to automatic review settings November 13, 2025 18:15
@Aaron1011
Copy link
Member Author

I'm not sure if this is related to #4326

Copilot finished reviewing on behalf of Aaron1011 November 13, 2025 18:17
Copy link
Contributor

Copilot AI left a 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_mut with Arc::into_inner to guarantee exactly one thread succeeds in extracting the inner value
  • Modified the dummy value to be wrapped in an Arc to work with the new std::mem::replace approach

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Aaron1011
Copy link
Member Author

#4595 will make this unnecessary, since the relevant logic is entirely removed in that PR

@virajmehta virajmehta added this pull request to the merge queue Nov 14, 2025
@Aaron1011 Aaron1011 removed this pull request from the merge queue due to a manual request Nov 14, 2025
@virajmehta virajmehta added this pull request to the merge queue Nov 14, 2025
@Aaron1011 Aaron1011 removed this pull request from the merge queue due to a manual request Nov 14, 2025
@Aaron1011 Aaron1011 marked this pull request as draft November 14, 2025 16:10
@Aaron1011
Copy link
Member Author

I'm going to merge #4595 instead

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.

3 participants