HubSwitchGuard should not be Send
How do you use Sentry?
Sentry SaaS (sentry.io)
SDK version
0.46.0
Steps to reproduce
-
let sg = HubSwitchGuard::new(Hub::current()) -
std::thread::spawn(move|| { let _ = sg; }
Expected result
Compilation error
Actual result
New thread gets its hub replaced by that of the parent thread, and parent thread never recovers their own hub.
Because HubSwitchGuard is about managing the thread-local that represents the current hub for this thread, it really doesn't make sense to move it to another thread, and as such that should be prevented. (HubSwitchGuard should be !Send)
This can be achieved with e.g. a field like this _make_type_not_send: std::marker::PhantomData<std::sync::MutexGuard<'static, ()>>,
Hmm probably making it !Sync would cause issues because it couldn't be used here: https://github.com/getsentry/sentry-rust/blob/196501d8fa067bdf35b7c95261f6b7fe7bb84bb8/sentry-tracing/src/layer.rs#L374
Hi, thanks for reporting, I will investigate further and get back to you