Skip to content

Commit 28e2389

Browse files
adinauerclaude
andauthored
fix(spring): Prevent Reactor pool scope chain leaks (#6283)
* fix(spring): Prevent Reactor pool scope chain leaks Skip scope propagation for Reactor pool maintenance tasks that reschedule themselves indefinitely. This prevents each run from retaining the previous run through the parent scope chain. Add a Reactor Netty connection pool regression test that verifies background eviction keeps scope depth bounded. Fixes GH-6248 Refs JAVA-773 Co-Authored-By: Claude <noreply@anthropic.com> * changelog * test(spring): Drop Reactor pool regression test Remove the Reactor Netty integration test and its test-only Truth dependency. Co-Authored-By: Claude <noreply@anthropic.com> * fix(spring): Refine Reactor pool runnable exclusions Exclude HTTP/2 eviction lambdas and narrow the existing Reactor Netty matches to maintenance lambdas. Keep standalone Reactor Pool acquisition delivery wrapped so request scopes continue to propagate. Add coverage for supported lambda class name shapes and request-carrying negative cases across all Spring integrations. Refs GH-6248 Refs JAVA-773 Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 5257183 commit 28e2389

7 files changed

Lines changed: 157 additions & 15 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
### Fixes
1111

1212
- Always remove the first-draw listener after the first frame, even if no layout pass follows it ([#6152](https://github.com/getsentry/sentry-java/pull/6152))
13+
- Prevent Reactor pool maintenance tasks from retaining unbounded Sentry scope chains ([#6283](https://github.com/getsentry/sentry-java/pull/6283))
1314

1415
## 8.61.1
1516

‎sentry-spring-7/src/main/java/io/sentry/spring7/webflux/SentryScheduleHook.java‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,31 @@ public final class SentryScheduleHook implements Function<Runnable, Runnable> {
2020
* scope parent chain buildup.
2121
*
2222
* @see <a href="https://github.com/getsentry/sentry-java/issues/5051">GitHub Issue #5051</a>
23+
* @see <a href="https://github.com/getsentry/sentry-java/issues/6248">GitHub Issue #6248</a>
2324
*/
2425
private static final String[] EXCLUDED_RUNNABLE_PREFIXES = {
25-
"reactor.kafka.receiver.internals.ConsumerEventLoop"
26+
"reactor.kafka.receiver.internals.ConsumerEventLoop",
27+
"reactor.netty.internal.shaded.reactor.pool.SimpleDequePool$$Lambda",
28+
"reactor.netty.http.client.Http2Pool$$Lambda",
29+
"reactor.netty.resources.PooledConnectionProvider$$Lambda"
2630
};
2731

28-
@Override
29-
public Runnable apply(final @NotNull Runnable runnable) {
30-
final String runnableClassName = runnable.getClass().getName();
32+
// The standalone reactor.pool.SimpleDequePool is intentionally not excluded because it also
33+
// schedules acquisition-delivery tasks that require scope propagation.
34+
static boolean isExcluded(final @NotNull String runnableClassName) {
3135
for (final String excludedPrefix : EXCLUDED_RUNNABLE_PREFIXES) {
3236
if (runnableClassName.startsWith(excludedPrefix)) {
33-
return runnable;
37+
return true;
3438
}
3539
}
40+
return false;
41+
}
42+
43+
@Override
44+
public Runnable apply(final @NotNull Runnable runnable) {
45+
if (isExcluded(runnable.getClass().getName())) {
46+
return runnable;
47+
}
3648

3749
final IScopes newScopes = Sentry.getCurrentScopes().forkedCurrentScope("spring.scheduleHook");
3850

‎sentry-spring-7/src/test/kotlin/io/sentry/spring7/webflux/SentryScheduleHookTest.kt‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import kotlin.test.AfterTest
88
import kotlin.test.BeforeTest
99
import kotlin.test.Test
1010
import kotlin.test.assertEquals
11+
import kotlin.test.assertFalse
1112
import kotlin.test.assertNotEquals
13+
import kotlin.test.assertTrue
1214

1315
class SentryScheduleHookTest {
1416
private val dsn = "http://key@localhost/proj"
@@ -55,4 +57,37 @@ class SentryScheduleHookTest {
5557
}
5658
.get()
5759
}
60+
61+
@Test
62+
fun `known maintenance runnable class names are excluded`() {
63+
val classNames =
64+
listOf(
65+
"reactor.kafka.receiver.internals.ConsumerEventLoop\$PollEvent",
66+
"reactor.netty.internal.shaded.reactor.pool.SimpleDequePool\$\$Lambda\$42/0x00000001",
67+
"reactor.netty.internal.shaded.reactor.pool.SimpleDequePool\$\$Lambda/0x00000001",
68+
"reactor.netty.http.client.Http2Pool\$\$Lambda\$42/0x00000001",
69+
"reactor.netty.http.client.Http2Pool\$\$Lambda/0x00000001",
70+
"reactor.netty.resources.PooledConnectionProvider\$\$Lambda\$42/0x00000001",
71+
"reactor.netty.resources.PooledConnectionProvider\$\$Lambda/0x00000001",
72+
)
73+
74+
classNames.forEach { className ->
75+
assertTrue(SentryScheduleHook.isExcluded(className), className)
76+
}
77+
}
78+
79+
@Test
80+
fun `request carrying runnable class names are not excluded`() {
81+
val classNames =
82+
listOf(
83+
"reactor.netty.http.client.Http2Pool\$Borrower",
84+
"reactor.netty.internal.shaded.reactor.pool.SimpleDequePool\$QueueBorrowerMono",
85+
"reactor.pool.SimpleDequePool\$\$Lambda\$42/0x00000001",
86+
"com.example.RequestTask",
87+
)
88+
89+
classNames.forEach { className ->
90+
assertFalse(SentryScheduleHook.isExcluded(className), className)
91+
}
92+
}
5893
}

‎sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/webflux/SentryScheduleHook.java‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,31 @@ public final class SentryScheduleHook implements Function<Runnable, Runnable> {
2020
* scope parent chain buildup.
2121
*
2222
* @see <a href="https://github.com/getsentry/sentry-java/issues/5051">GitHub Issue #5051</a>
23+
* @see <a href="https://github.com/getsentry/sentry-java/issues/6248">GitHub Issue #6248</a>
2324
*/
2425
private static final String[] EXCLUDED_RUNNABLE_PREFIXES = {
25-
"reactor.kafka.receiver.internals.ConsumerEventLoop"
26+
"reactor.kafka.receiver.internals.ConsumerEventLoop",
27+
"reactor.netty.internal.shaded.reactor.pool.SimpleDequePool$$Lambda",
28+
"reactor.netty.http.client.Http2Pool$$Lambda",
29+
"reactor.netty.resources.PooledConnectionProvider$$Lambda"
2630
};
2731

28-
@Override
29-
public Runnable apply(final @NotNull Runnable runnable) {
30-
final String runnableClassName = runnable.getClass().getName();
32+
// The standalone reactor.pool.SimpleDequePool is intentionally not excluded because it also
33+
// schedules acquisition-delivery tasks that require scope propagation.
34+
static boolean isExcluded(final @NotNull String runnableClassName) {
3135
for (final String excludedPrefix : EXCLUDED_RUNNABLE_PREFIXES) {
3236
if (runnableClassName.startsWith(excludedPrefix)) {
33-
return runnable;
37+
return true;
3438
}
3539
}
40+
return false;
41+
}
42+
43+
@Override
44+
public Runnable apply(final @NotNull Runnable runnable) {
45+
if (isExcluded(runnable.getClass().getName())) {
46+
return runnable;
47+
}
3648

3749
final IScopes newScopes = Sentry.getCurrentScopes().forkedCurrentScope("spring.scheduleHook");
3850

‎sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/webflux/SentryScheduleHookTest.kt‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import kotlin.test.AfterTest
88
import kotlin.test.BeforeTest
99
import kotlin.test.Test
1010
import kotlin.test.assertEquals
11+
import kotlin.test.assertFalse
1112
import kotlin.test.assertNotEquals
13+
import kotlin.test.assertTrue
1214

1315
class SentryScheduleHookTest {
1416
private val dsn = "http://key@localhost/proj"
@@ -55,4 +57,37 @@ class SentryScheduleHookTest {
5557
}
5658
.get()
5759
}
60+
61+
@Test
62+
fun `known maintenance runnable class names are excluded`() {
63+
val classNames =
64+
listOf(
65+
"reactor.kafka.receiver.internals.ConsumerEventLoop\$PollEvent",
66+
"reactor.netty.internal.shaded.reactor.pool.SimpleDequePool\$\$Lambda\$42/0x00000001",
67+
"reactor.netty.internal.shaded.reactor.pool.SimpleDequePool\$\$Lambda/0x00000001",
68+
"reactor.netty.http.client.Http2Pool\$\$Lambda\$42/0x00000001",
69+
"reactor.netty.http.client.Http2Pool\$\$Lambda/0x00000001",
70+
"reactor.netty.resources.PooledConnectionProvider\$\$Lambda\$42/0x00000001",
71+
"reactor.netty.resources.PooledConnectionProvider\$\$Lambda/0x00000001",
72+
)
73+
74+
classNames.forEach { className ->
75+
assertTrue(SentryScheduleHook.isExcluded(className), className)
76+
}
77+
}
78+
79+
@Test
80+
fun `request carrying runnable class names are not excluded`() {
81+
val classNames =
82+
listOf(
83+
"reactor.netty.http.client.Http2Pool\$Borrower",
84+
"reactor.netty.internal.shaded.reactor.pool.SimpleDequePool\$QueueBorrowerMono",
85+
"reactor.pool.SimpleDequePool\$\$Lambda\$42/0x00000001",
86+
"com.example.RequestTask",
87+
)
88+
89+
classNames.forEach { className ->
90+
assertFalse(SentryScheduleHook.isExcluded(className), className)
91+
}
92+
}
5893
}

‎sentry-spring/src/main/java/io/sentry/spring/webflux/SentryScheduleHook.java‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,31 @@ public final class SentryScheduleHook implements Function<Runnable, Runnable> {
2020
* scope parent chain buildup.
2121
*
2222
* @see <a href="https://github.com/getsentry/sentry-java/issues/5051">GitHub Issue #5051</a>
23+
* @see <a href="https://github.com/getsentry/sentry-java/issues/6248">GitHub Issue #6248</a>
2324
*/
2425
private static final String[] EXCLUDED_RUNNABLE_PREFIXES = {
25-
"reactor.kafka.receiver.internals.ConsumerEventLoop"
26+
"reactor.kafka.receiver.internals.ConsumerEventLoop",
27+
"reactor.netty.internal.shaded.reactor.pool.SimpleDequePool$$Lambda",
28+
"reactor.netty.http.client.Http2Pool$$Lambda",
29+
"reactor.netty.resources.PooledConnectionProvider$$Lambda"
2630
};
2731

28-
@Override
29-
public Runnable apply(final @NotNull Runnable runnable) {
30-
final String runnableClassName = runnable.getClass().getName();
32+
// The standalone reactor.pool.SimpleDequePool is intentionally not excluded because it also
33+
// schedules acquisition-delivery tasks that require scope propagation.
34+
static boolean isExcluded(final @NotNull String runnableClassName) {
3135
for (final String excludedPrefix : EXCLUDED_RUNNABLE_PREFIXES) {
3236
if (runnableClassName.startsWith(excludedPrefix)) {
33-
return runnable;
37+
return true;
3438
}
3539
}
40+
return false;
41+
}
42+
43+
@Override
44+
public Runnable apply(final @NotNull Runnable runnable) {
45+
if (isExcluded(runnable.getClass().getName())) {
46+
return runnable;
47+
}
3648

3749
final IScopes newScopes = Sentry.getCurrentScopes().forkedCurrentScope("spring.scheduleHook");
3850

‎sentry-spring/src/test/kotlin/io/sentry/spring/webflux/SentryScheduleHookTest.kt‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import kotlin.test.AfterTest
88
import kotlin.test.BeforeTest
99
import kotlin.test.Test
1010
import kotlin.test.assertEquals
11+
import kotlin.test.assertFalse
1112
import kotlin.test.assertNotEquals
13+
import kotlin.test.assertTrue
1214

1315
class SentryScheduleHookTest {
1416
private val dsn = "http://key@localhost/proj"
@@ -55,4 +57,37 @@ class SentryScheduleHookTest {
5557
}
5658
.get()
5759
}
60+
61+
@Test
62+
fun `known maintenance runnable class names are excluded`() {
63+
val classNames =
64+
listOf(
65+
"reactor.kafka.receiver.internals.ConsumerEventLoop\$PollEvent",
66+
"reactor.netty.internal.shaded.reactor.pool.SimpleDequePool\$\$Lambda\$42/0x00000001",
67+
"reactor.netty.internal.shaded.reactor.pool.SimpleDequePool\$\$Lambda/0x00000001",
68+
"reactor.netty.http.client.Http2Pool\$\$Lambda\$42/0x00000001",
69+
"reactor.netty.http.client.Http2Pool\$\$Lambda/0x00000001",
70+
"reactor.netty.resources.PooledConnectionProvider\$\$Lambda\$42/0x00000001",
71+
"reactor.netty.resources.PooledConnectionProvider\$\$Lambda/0x00000001",
72+
)
73+
74+
classNames.forEach { className ->
75+
assertTrue(SentryScheduleHook.isExcluded(className), className)
76+
}
77+
}
78+
79+
@Test
80+
fun `request carrying runnable class names are not excluded`() {
81+
val classNames =
82+
listOf(
83+
"reactor.netty.http.client.Http2Pool\$Borrower",
84+
"reactor.netty.internal.shaded.reactor.pool.SimpleDequePool\$QueueBorrowerMono",
85+
"reactor.pool.SimpleDequePool\$\$Lambda\$42/0x00000001",
86+
"com.example.RequestTask",
87+
)
88+
89+
classNames.forEach { className ->
90+
assertFalse(SentryScheduleHook.isExcluded(className), className)
91+
}
92+
}
5893
}

0 commit comments

Comments
 (0)