Skip to content

get_slow with THREAD_GUARD can trigger: cannot access a Thread Local Storage value during or after destruction: AccessError #74

Description

@gerwin3

I'm trying to get to the bottom of a weird crash I'm getting. I have minimal reproducible here:

https://github.com/gerwin3/thread-local-accesserror-repro/blob/main/src/main.rs

System:

  • Arch Linux x86_64 6.7.6-arch1-1
  • AMD Ryzen 9 5900X

To trigger the crash: close the window with CTRL + W.

The app uses egui and tracing-appender and the combination somehow triggers an AccessError (cannot access a Thread Local Storage value during or after destruction: AccessError) that eventually is caused by a function get_slow in thread_local:

THREAD_GUARD.with(|guard| guard.id.set(new.id));

My guess is that calling with on a thread local may not always be correct if the caller is running a destructor (?) in any case the docs of LocalKey::with seem to suggest so: https://doc.rust-lang.org/std/thread/struct.LocalKey.html#method.with

Not sure if I'm on the right track here. But since the documentation on this crate does not seem to suggest that ThreadLocal::get can panic in certain situations, and it seems it can actually panic in this case it seems this is a bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions