Skip to content

Commit

Permalink
move terminate callback invocation
Browse files Browse the repository at this point in the history
  • Loading branch information
Noah-Kennedy committed Aug 14, 2024
1 parent ca2e0d9 commit 4247933
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions tokio/src/runtime/task/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,17 +314,9 @@ where

let snapshot = self.state().transition_to_complete();

// We catch panics here in case dropping the future, invoking a hook or waking the
// We catch panics here in case dropping the future or waking the
// JoinHandle panics.
let _ = panic::catch_unwind(panic::AssertUnwindSafe(|| {
if let Some(f) = self.trailer().hooks.task_terminate_callback.as_ref() {
f(&TaskMeta {
#[cfg(tokio_unstable)]
id: self.core().task_id,
_phantom: Default::default(),
})
}

if !snapshot.is_join_interested() {
// The `JoinHandle` is not interested in the output of
// this task. It is our responsibility to drop the
Expand All @@ -338,6 +330,20 @@ where
}
}));

// We catch panics here in case invoking a hook panics.
//
// We call this in a separate block so that it runs after the task appears to have
// completed and will still run if the destructor panics.
let _ = panic::catch_unwind(panic::AssertUnwindSafe(|| {
if let Some(f) = self.trailer().hooks.task_terminate_callback.as_ref() {
f(&TaskMeta {
#[cfg(tokio_unstable)]
id: self.core().task_id,
_phantom: Default::default(),
})
}
}));

// The task has completed execution and will no longer be scheduled.
let num_release = self.release();

Expand Down

0 comments on commit 4247933

Please sign in to comment.