Thread 'worker thread 0' panicked at 'cannot access a TLS value during or after it is destroyed: AccessError', src/libcore/result.rs:1084:5

Hello,
I'm working on a client-server system that communicates using Remote Procedure Call. The system uses some rust wrappers of C++ functions to do computations over query/reply.

When I launch a server process and two client processes, I got the following errors:

  • Server: thread 'worker thread 0' panicked at 'cannot access a TLS value during or after it is destroyed: AccessError', src/libcore/result.rs:1084:5
  • Client1: thread 'main' panicked at 'top level error: Error { kind: Disconnected, description: "Connection reset by peer (os error 104)" }', src/libcore/result.rs:1084:5
  • Client2: thread 'main' panicked at 'top level error: Error { kind: Disconnected, description: "Peer disconnected." }', src/libcore/result.rs:1084:5

Here are some relevant stack trace pieces from the server process:
8: rust_begin_unwind
9: core::panicking::panic_fmt
10: core::result::unwrap_failed
11: core::result::Result<T,E>::expect
12: std:: thread::local::LocalKey::with
13: gj::private::with_current_event_loop
14: <gj::private::EventDropper as core::ops::drop::Drop>::drop
15: core::ptr::real_drop_in_place

I would appreciate if someone can give me clues about the cause of this error. Right now I have no idea where to start debugging... Thank you!

13: gj::private::with_current_event_loop
14: <gj::private::EventDropper as core::ops::drop::Drop>::drop

This looks suspicious. Why do you need to access the event loop in a drop implementation? The problem here is I think that you attempt to access the event loop, but it is currently in the process of being dropped. I assume this dropping drops the EventDropper.

2 Likes