Skip to content

Commit f6787f3

Browse files
authored
Merge branch 'main' into fix/app-start-warm-detection
2 parents fec2342 + e873777 commit f6787f3

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
@@ -29,10 +29,9 @@
2929
debugImplementation("io.sentry:sentry-spotlight:<version>")
3030
}
3131
```
32-
33-
### Fixes
34-
3532
- Fix scroll target detection for Jetpack Compose ([#5017](https://github.com/getsentry/sentry-java/pull/5017))
33+
- No longer fork Sentry `Scopes` for `reactor-kafka` consumer poll `Runnable` ([#5080](https://github.com/getsentry/sentry-java/pull/5080))
34+
- 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.
3635

3736
### Internal
3837

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)