Skip to content

Commit 4d97e1c

Browse files
committed
tokio: don't panic if taskdump request is cancelled
ref: tokio-rs#5717 (comment)
1 parent ce6f01f commit 4d97e1c

File tree

5 files changed

+6
-14
lines changed

5 files changed

+6
-14
lines changed

examples/dump.rs

-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ async fn main() {
4545
_ = tokio::spawn(c()) => {},
4646
_ = dump() => {},
4747
);
48-
4948
}
5049

5150
#[cfg(not(all(

tokio/src/runtime/handle.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ cfg_taskdump! {
346346
scheduler::Handle::CurrentThread(handle) => handle.dump(),
347347
#[cfg(all(feature = "rt-multi-thread", not(tokio_wasi)))]
348348
scheduler::Handle::MultiThread(handle) => {
349-
// perform the trace in a separate thread so that the
349+
// perform the trace in a separate thread so that the
350350
// trace itself does not appear in the taskdump.
351351
let handle = handle.clone();
352352
spawn_thread(|| {
@@ -366,9 +366,7 @@ cfg_taskdump! {
366366
{
367367
let (tx, rx) = crate::sync::oneshot::channel();
368368
crate::loom::thread::spawn(|| {
369-
if tx.send(f()).is_err() {
370-
unreachable!("send failed");
371-
}
369+
let _ = tx.send(f());
372370
});
373371
rx.await.unwrap()
374372
}

tokio/src/runtime/scheduler/multi_thread/worker.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -908,11 +908,7 @@ impl Core {
908908

909909
if !self.is_traced {
910910
// Check if the worker should be tracing.
911-
self.is_traced = worker
912-
.handle
913-
.shared
914-
.trace_status
915-
.trace_requested();
911+
self.is_traced = worker.handle.shared.trace_status.trace_requested();
916912
}
917913
}
918914

@@ -1095,7 +1091,7 @@ impl Handle {
10951091
}
10961092
}
10971093

1098-
cfg_taskdump!{
1094+
cfg_taskdump! {
10991095
fn trace_core(&self, mut core: Box<Core>) -> Box<Core> {
11001096
use crate::runtime::dump;
11011097
use task::trace::trace_multi_thread;

tokio/src/runtime/task/trace/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,6 @@ pub(in crate::runtime) fn trace_multi_thread(
290290
let ((), trace) = Trace::capture(|| task.as_raw().poll());
291291
traces.push(trace);
292292

293-
294293
// reschedule the task
295294
let _ = task.as_raw().state().transition_to_notified_by_ref();
296295
task.as_raw().schedule();

tokio/tests/dump.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ fn current_thread() {
5757
_ = tokio::spawn(a()) => {},
5858
_ = tokio::spawn(a()) => {},
5959
_ = dump() => {},
60-
);
60+
);
6161
});
6262
}
6363

@@ -93,6 +93,6 @@ fn multi_thread() {
9393
_ = tokio::spawn(a()) => {},
9494
_ = tokio::spawn(a()) => {},
9595
_ = dump() => {},
96-
);
96+
);
9797
});
9898
}

0 commit comments

Comments
 (0)