sentry-rust icon indicating copy to clipboard operation
sentry-rust copied to clipboard

HubSwitchGuard should not be Send

Open Ten0 opened this issue 1 month ago • 3 comments

How do you use Sentry?

Sentry SaaS (sentry.io)

SDK version

0.46.0

Steps to reproduce

  1. let sg = HubSwitchGuard::new(Hub::current())
  2. 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, ()>>,

Ten0 avatar Dec 04 '25 17:12 Ten0

RUST-130

linear[bot] avatar Dec 04 '25 17:12 linear[bot]

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

Ten0 avatar Dec 04 '25 18:12 Ten0

Hi, thanks for reporting, I will investigate further and get back to you

szokeasaurusrex avatar Dec 10 '25 09:12 szokeasaurusrex