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

AccessError when dropping a mpsc channel stored in a thread local #6091

Closed
duarten opened this issue Oct 20, 2023 · 1 comment · Fixed by #6148
Closed

AccessError when dropping a mpsc channel stored in a thread local #6091

duarten opened this issue Oct 20, 2023 · 1 comment · Fixed by #6148
Labels
A-tokio Area: The main tokio crate C-bug Category: This is a bug.

Comments

@duarten
Copy link
Contributor

duarten commented Oct 20, 2023

Version

v1.33.0

Platform

macOS and Linux.

Description

When storing a mpsc::chan in a thread local, I get an AccessError when dropping it:

thread '<unnamed>' panicked at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/thread/local.rs:246:26:
cannot access a Thread Local Storage value during or after destruction: AccessError
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread '<unnamed>' panicked at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/thread/local.rs:246:26:
cannot access a Thread Local Storage value during or after destruction: AccessError
stack backtrace:
   0:        0x1046b4b24 - std::backtrace_rs::backtrace::libunwind::trace::h815672f5996c9e34
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:        0x1046b4b24 - std::backtrace_rs::backtrace::trace_unsynchronized::h2e094b2d8c270437
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:        0x1046b4b24 - std::sys_common::backtrace::_print_fmt::hae24b71afea95695
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys_common/backtrace.rs:67:5
   3:        0x1046b4b24 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h6d4268b2ed62fb94
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys_common/backtrace.rs:44:22
   4:        0x1044c097c - core::fmt::rt::Argument::fmt::h835101b6de0df17f
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/fmt/rt.rs:138:9
   5:        0x1044c097c - core::fmt::write::h5d55d44549819258
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/fmt/mod.rs:1094:21
   6:        0x1046b11ac - std::io::Write::write_fmt::hc515897f91abd6cf
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/io/mod.rs:1714:15
   7:        0x1046b4924 - std::sys_common::backtrace::_print::h5844dab5cfa39fca
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys_common/backtrace.rs:47:5
   8:        0x1046b4924 - std::sys_common::backtrace::print::h2c300c1ebedfc73c
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys_common/backtrace.rs:34:9
   9:        0x1046b5e30 - std::panicking::default_hook::{{closure}}::h0aa9be5c44269370
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:270:22
  10:        0x1046b5b80 - std::panicking::default_hook::h2c0ef097934ee9e6
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:290:9
  11:        0x1046b63fc - std::panicking::rust_panic_with_hook::h84c8637cb6e56008
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:707:13
  12:        0x1046b6204 - std::panicking::begin_panic_handler::{{closure}}::h25482adda06c7b7f
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:599:13
  13:        0x1046b4f9c - std::sys_common::backtrace::__rust_end_short_backtrace::h0c6f3beb22324a29
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys_common/backtrace.rs:170:18
  14:        0x1046b5fb0 - rust_begin_unwind
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:595:5
  15:        0x10472ac44 - core::panicking::panic_fmt::h9072a0246ecafd14
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/panicking.rs:67:14
  16:        0x10472af34 - core::result::unwrap_failed::hd7600d03a3086be4
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/result.rs:1652:5
  17:        0x1046ee3cc - core::result::Result<T,E>::expect::hd2106338a094706e
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/result.rs:1034:23
  18:        0x1046ee3cc - std::thread::local::LocalKey<T>::with::hbee999b7c3c237fd
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/thread/local.rs:246:9
  19:        0x1046ee3cc - tokio::runtime::context::with_scheduler::hac1d7f063edd4d44
                               at .cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.33.0/src/runtime/context.rs:181:17
  20:        0x1046ee3cc - tokio::runtime::scheduler::multi_thread::worker::with_current::h6d404196bc8e7b01
                               at .cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.33.0/src/runtime/scheduler/multi_thread/worker.rs:1213:5
  21:        0x1046ee3cc - tokio::runtime::scheduler::multi_thread::worker::<impl tokio::runtime::scheduler::multi_thread::handle::Handle>::schedule_task::hbe4870a7671ee892
                               at .cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.33.0/src/runtime/scheduler/multi_thread/worker.rs:1013:9
  22:        0x1046f8574 - tokio::runtime::task::raw::RawTask::schedule::hef2762f7fc30dba4
                               at .cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.33.0/src/runtime/task/raw.rs:205:18
  23:        0x1046f8574 - tokio::runtime::task::harness::<impl tokio::runtime::task::raw::RawTask>::wake_by_val::hab005308c524fd21
                               at .cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.33.0/src/runtime/task/harness.rs:78:17
  24:        0x1046f8574 - tokio::runtime::task::waker::wake_by_val::h4173dc2a7952689e
                               at .cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.33.0/src/runtime/task/waker.rs:85:5
  25:        0x1046c531c - core::task::wake::Waker::wake::he9f26a5a169f6b60
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/task/wake.rs:281:18
  26:        0x1046c531c - tokio::sync::task::atomic_waker::AtomicWaker::wake::h176f2aa71beac0ad
                               at .cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.33.0/src/sync/task/atomic_waker.rs:307:19
  27:        0x1046c531c - tokio::sync::mpsc::chan::Tx<T,S>::wake_rx::h09a836542d958038
                               at .cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.33.0/src/sync/mpsc/chan.rs:167:9
  28:        0x1046c531c - <tokio::sync::mpsc::chan::Tx<T,S> as core::ops::drop::Drop>::drop::ha7788990a5697371
                               at .cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.33.0/src/sync/mpsc/chan.rs:216:14
  29:        0x1046c531c - core::ptr::drop_in_place<tokio::sync::mpsc::chan::Tx<u64,tokio::sync::mpsc::unbounded::Semaphore>>::h908829beab9fe900
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/ptr/mod.rs:497:1
  30:        0x1046c531c - core::ptr::drop_in_place<tokio::sync::mpsc::unbounded::UnboundedSender<u64>>::h772a8a40fc2babfc
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/ptr/mod.rs:497:1

This is because mpsc::chan::drop calls into the context.

@duarten duarten added A-tokio Area: The main tokio crate C-bug Category: This is a bug. labels Oct 20, 2023
@Darksonn
Copy link
Contributor

It appears that this is because sending a wakeup accesses a thread-local. Thanks for reporting this.

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 C-bug Category: This is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants