forked from tokio-rs/tokio
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
runtime: swallow panics in drop(join_handle)
fixes tokio-rs#4412 From the issue description: > In Tokio, panics are generally caught and not passed resumed when dropping the JoinHandle, however when dropping the JoinHandle of a task that has already completed, that panic can propagate to the user who dropped the JoinHandle. This PR fixes that.
- Loading branch information
Showing
2 changed files
with
21 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#![warn(rust_2018_idioms)] | ||
#![cfg(feature = "full")] | ||
|
||
struct PanicsOnDrop; | ||
|
||
impl Drop for PanicsOnDrop { | ||
fn drop(&mut self) { | ||
panic!("I told you so"); | ||
} | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_panics_do_not_propagate_when_dropping_join_handle() { | ||
let join_handle = tokio::spawn(async move { PanicsOnDrop }); | ||
|
||
// only drop the JoinHandle when the task has completed | ||
// (which is difficult to synchronize precisely) | ||
tokio::time::sleep(std::time::Duration::from_millis(3)).await; | ||
drop(join_handle); | ||
} |