Skip to content

Commit 5eb00f6

Browse files
authored
fix: Avoid deadlock when nesting configure_scope (#256)
1 parent ad30b91 commit 5eb00f6

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

sentry-core/src/hub.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -396,11 +396,8 @@ impl Hub {
396396
F: FnOnce(&mut Scope) -> R,
397397
{
398398
with_client_impl! {{
399-
let (new_scope, rv) = self.with_current_scope(|scope| {
400-
let mut new_scope = (**scope).clone();
401-
let rv = f(&mut new_scope);
402-
(new_scope, rv)
403-
});
399+
let mut new_scope = self.with_current_scope(|scope| scope.clone());
400+
let rv = f(&mut new_scope);
404401
self.with_current_scope_mut(|ptr| *ptr = new_scope);
405402
rv
406403
}}
@@ -440,7 +437,7 @@ impl Hub {
440437
}
441438

442439
#[cfg(feature = "client")]
443-
pub(crate) fn with_current_scope<F: FnOnce(&Arc<Scope>) -> R, R>(&self, f: F) -> R {
440+
pub(crate) fn with_current_scope<F: FnOnce(&Scope) -> R, R>(&self, f: F) -> R {
444441
self.inner.with(|stack| f(&stack.top().scope))
445442
}
446443

sentry/tests/test_basic.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,22 @@ fn test_factory() {
120120

121121
assert_eq!(events.load(Ordering::SeqCst), 1);
122122
}
123+
124+
#[test]
125+
fn test_reentrant_configure_scope() {
126+
let events = sentry::test::with_captured_events(|| {
127+
sentry::configure_scope(|scope1| {
128+
scope1.set_tag("which_scope", "scope1");
129+
130+
sentry::configure_scope(|scope2| {
131+
scope2.set_tag("which_scope", "scope2");
132+
});
133+
});
134+
135+
sentry::capture_message("look ma, no deadlock!", sentry::Level::Info);
136+
});
137+
138+
assert_eq!(events.len(), 1);
139+
// well, the "outer" `configure_scope` wins
140+
assert_eq!(events[0].tags["which_scope"], "scope1");
141+
}

0 commit comments

Comments
 (0)