diff --git a/sentry-core/src/hub.rs b/sentry-core/src/hub.rs index 568919d84..5c05ddeb7 100644 --- a/sentry-core/src/hub.rs +++ b/sentry-core/src/hub.rs @@ -396,11 +396,8 @@ impl Hub { F: FnOnce(&mut Scope) -> R, { with_client_impl! {{ - let (new_scope, rv) = self.with_current_scope(|scope| { - let mut new_scope = (**scope).clone(); - let rv = f(&mut new_scope); - (new_scope, rv) - }); + let mut new_scope = self.with_current_scope(|scope| scope.clone()); + let rv = f(&mut new_scope); self.with_current_scope_mut(|ptr| *ptr = new_scope); rv }} @@ -440,7 +437,7 @@ impl Hub { } #[cfg(feature = "client")] - pub(crate) fn with_current_scope) -> R, R>(&self, f: F) -> R { + pub(crate) fn with_current_scope R, R>(&self, f: F) -> R { self.inner.with(|stack| f(&stack.top().scope)) } diff --git a/sentry/tests/test_basic.rs b/sentry/tests/test_basic.rs index 93297b6a4..33f5607dc 100644 --- a/sentry/tests/test_basic.rs +++ b/sentry/tests/test_basic.rs @@ -120,3 +120,22 @@ fn test_factory() { assert_eq!(events.load(Ordering::SeqCst), 1); } + +#[test] +fn test_reentrant_configure_scope() { + let events = sentry::test::with_captured_events(|| { + sentry::configure_scope(|scope1| { + scope1.set_tag("which_scope", "scope1"); + + sentry::configure_scope(|scope2| { + scope2.set_tag("which_scope", "scope2"); + }); + }); + + sentry::capture_message("look ma, no deadlock!", sentry::Level::Info); + }); + + assert_eq!(events.len(), 1); + // well, the "outer" `configure_scope` wins + assert_eq!(events[0].tags["which_scope"], "scope1"); +}