Skip to content

Commit 25104b7

Browse files
committed
No longer fork Sentry Scopes for reactor-kafka consumer poll Runnable
1 parent dc4cc7a commit 25104b7

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,27 @@
1313
*/
1414
@ApiStatus.Experimental
1515
public final class SentryScheduleHook implements Function<Runnable, Runnable> {
16+
17+
/**
18+
* Runnable class names that should be excluded from scope forking. These are typically internal
19+
* scheduler loops that reschedule themselves indefinitely, which would cause memory issues due to
20+
* scope parent chain buildup.
21+
*
22+
* @see <a href="https://github.com/getsentry/sentry-java/issues/5051">GitHub Issue #5051</a>
23+
*/
24+
private static final String[] EXCLUDED_RUNNABLE_PREFIXES = {
25+
"reactor.kafka.receiver.internals.ConsumerEventLoop"
26+
};
27+
1628
@Override
1729
public Runnable apply(final @NotNull Runnable runnable) {
30+
final String runnableClassName = runnable.getClass().getName();
31+
for (final String excludedPrefix : EXCLUDED_RUNNABLE_PREFIXES) {
32+
if (runnableClassName.startsWith(excludedPrefix)) {
33+
return runnable;
34+
}
35+
}
36+
1837
final IScopes newScopes = Sentry.getCurrentScopes().forkedCurrentScope("spring.scheduleHook");
1938

2039
return () -> {

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,27 @@
1313
*/
1414
@ApiStatus.Experimental
1515
public final class SentryScheduleHook implements Function<Runnable, Runnable> {
16+
17+
/**
18+
* Runnable class names that should be excluded from scope forking. These are typically internal
19+
* scheduler loops that reschedule themselves indefinitely, which would cause memory issues due to
20+
* scope parent chain buildup.
21+
*
22+
* @see <a href="https://github.com/getsentry/sentry-java/issues/5051">GitHub Issue #5051</a>
23+
*/
24+
private static final String[] EXCLUDED_RUNNABLE_PREFIXES = {
25+
"reactor.kafka.receiver.internals.ConsumerEventLoop"
26+
};
27+
1628
@Override
1729
public Runnable apply(final @NotNull Runnable runnable) {
30+
final String runnableClassName = runnable.getClass().getName();
31+
for (final String excludedPrefix : EXCLUDED_RUNNABLE_PREFIXES) {
32+
if (runnableClassName.startsWith(excludedPrefix)) {
33+
return runnable;
34+
}
35+
}
36+
1837
final IScopes newScopes = Sentry.getCurrentScopes().forkedCurrentScope("spring.scheduleHook");
1938

2039
return () -> {

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,27 @@
1313
*/
1414
@ApiStatus.Experimental
1515
public final class SentryScheduleHook implements Function<Runnable, Runnable> {
16+
17+
/**
18+
* Runnable class names that should be excluded from scope forking. These are typically internal
19+
* scheduler loops that reschedule themselves indefinitely, which would cause memory issues due to
20+
* scope parent chain buildup.
21+
*
22+
* @see <a href="https://github.com/getsentry/sentry-java/issues/5051">GitHub Issue #5051</a>
23+
*/
24+
private static final String[] EXCLUDED_RUNNABLE_PREFIXES = {
25+
"reactor.kafka.receiver.internals.ConsumerEventLoop"
26+
};
27+
1628
@Override
1729
public Runnable apply(final @NotNull Runnable runnable) {
30+
final String runnableClassName = runnable.getClass().getName();
31+
for (final String excludedPrefix : EXCLUDED_RUNNABLE_PREFIXES) {
32+
if (runnableClassName.startsWith(excludedPrefix)) {
33+
return runnable;
34+
}
35+
}
36+
1837
final IScopes newScopes = Sentry.getCurrentScopes().forkedCurrentScope("spring.scheduleHook");
1938

2039
return () -> {

0 commit comments

Comments
 (0)