Skip to content

Commit 7f999af

Browse files
authored
Merge branch 'main' into rz/fix/tests-cleanup
2 parents 7277e52 + e873777 commit 7f999af

File tree

4 files changed

+59
-3
lines changed

4 files changed

+59
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@
2525
debugImplementation("io.sentry:sentry-spotlight:<version>")
2626
}
2727
```
28-
29-
### Fixes
30-
3128
- Fix scroll target detection for Jetpack Compose ([#5017](https://github.com/getsentry/sentry-java/pull/5017))
29+
- No longer fork Sentry `Scopes` for `reactor-kafka` consumer poll `Runnable` ([#5080](https://github.com/getsentry/sentry-java/pull/5080))
30+
- This was causing a memory leak because `reactor-kafka`'s poll event reschedules itself infinitely, and each invocation of `SentryScheduleHook` created forked scopes with a parent reference, building an unbounded chain that couldn't be garbage collected.
3231

3332
### Internal
3433

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)