Skip to content

Commit

Permalink
tokio: don't panic if taskdump request is cancelled
Browse files Browse the repository at this point in the history
  • Loading branch information
jswrenn committed May 30, 2023
1 parent ce6f01f commit 4d97e1c
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 14 deletions.
1 change: 0 additions & 1 deletion examples/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ async fn main() {
_ = tokio::spawn(c()) => {},
_ = dump() => {},
);

}

#[cfg(not(all(
Expand Down
6 changes: 2 additions & 4 deletions tokio/src/runtime/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ cfg_taskdump! {
scheduler::Handle::CurrentThread(handle) => handle.dump(),
#[cfg(all(feature = "rt-multi-thread", not(tokio_wasi)))]
scheduler::Handle::MultiThread(handle) => {
// perform the trace in a separate thread so that the
// perform the trace in a separate thread so that the
// trace itself does not appear in the taskdump.
let handle = handle.clone();
spawn_thread(|| {
Expand All @@ -366,9 +366,7 @@ cfg_taskdump! {
{
let (tx, rx) = crate::sync::oneshot::channel();
crate::loom::thread::spawn(|| {
if tx.send(f()).is_err() {
unreachable!("send failed");
}
let _ = tx.send(f());
});
rx.await.unwrap()
}
Expand Down
8 changes: 2 additions & 6 deletions tokio/src/runtime/scheduler/multi_thread/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -908,11 +908,7 @@ impl Core {

if !self.is_traced {
// Check if the worker should be tracing.
self.is_traced = worker
.handle
.shared
.trace_status
.trace_requested();
self.is_traced = worker.handle.shared.trace_status.trace_requested();
}
}

Expand Down Expand Up @@ -1095,7 +1091,7 @@ impl Handle {
}
}

cfg_taskdump!{
cfg_taskdump! {
fn trace_core(&self, mut core: Box<Core>) -> Box<Core> {
use crate::runtime::dump;
use task::trace::trace_multi_thread;
Expand Down
1 change: 0 additions & 1 deletion tokio/src/runtime/task/trace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ pub(in crate::runtime) fn trace_multi_thread(
let ((), trace) = Trace::capture(|| task.as_raw().poll());
traces.push(trace);


// reschedule the task
let _ = task.as_raw().state().transition_to_notified_by_ref();
task.as_raw().schedule();
Expand Down
4 changes: 2 additions & 2 deletions tokio/tests/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn current_thread() {
_ = tokio::spawn(a()) => {},
_ = tokio::spawn(a()) => {},
_ = dump() => {},
);
);
});
}

Expand Down Expand Up @@ -93,6 +93,6 @@ fn multi_thread() {
_ = tokio::spawn(a()) => {},
_ = tokio::spawn(a()) => {},
_ = dump() => {},
);
);
});
}

0 comments on commit 4d97e1c

Please sign in to comment.