Skip to content
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

sync: handle panic during mpsc drop #7094

Merged
merged 2 commits into from
Jan 13, 2025
Merged

Conversation

mox692
Copy link
Member

@mox692 mox692 commented Jan 13, 2025

This PR updates the mpsc to handle panics during the drop. Specifically, the chan::Rx will continue executing its drop even if a panic occurs during the drop.

Although this scenario is expected to be rare, there could be edge cases, for example:

  • On thread1, chan::Rx is dropped
  • On thread1, panic occurs in the middle of the drop
  • On thread2, chan::Chan is dropped (resuming from the interrupted element)
  • On thread2, panic occurs in the middle of the drop (no double panic since it's in a different thread)
  • The program continues with elements still remaining in the chan::Chan

This PR prevents such cases by enforcing a double panic on thread1.

@mox692 mox692 added A-tokio Area: The main tokio crate M-sync Module: tokio/sync labels Jan 13, 2025
@github-actions github-actions bot added the R-loom-sync Run loom sync tests on this PR label Jan 13, 2025
Copy link
Contributor

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good, thanks!

tokio/src/sync/mpsc/chan.rs Outdated Show resolved Hide resolved
Co-authored-by: Alice Ryhl <[email protected]>
@Darksonn Darksonn merged commit a82bdee into tokio-rs:master Jan 13, 2025
84 checks passed
@mox692 mox692 deleted the mpsc_drop branch January 14, 2025 02:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate M-sync Module: tokio/sync R-loom-sync Run loom sync tests on this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants