René's URL Explorer Experiment


Title: Memory Leak Observed: SentryScheduleHook + Reactor Kafka Interaction · Issue #5051 · getsentry/sentry-java · GitHub

Open Graph Title: Memory Leak Observed: SentryScheduleHook + Reactor Kafka Interaction · Issue #5051 · getsentry/sentry-java

X Title: Memory Leak Observed: SentryScheduleHook + Reactor Kafka Interaction · Issue #5051 · getsentry/sentry-java

Description: Integration sentry-spring-boot-starter-jakarta Java Version 21 Version 8.29.0 Steps to Reproduce Summary We observed a memory leak when using Sentry Java SDK with Reactor Kafka. The leak occurs even when idle (no messages), leading to Ou...

Open Graph Description: Integration sentry-spring-boot-starter-jakarta Java Version 21 Version 8.29.0 Steps to Reproduce Summary We observed a memory leak when using Sentry Java SDK with Reactor Kafka. The leak occurs eve...

X Description: Integration sentry-spring-boot-starter-jakarta Java Version 21 Version 8.29.0 Steps to Reproduce Summary We observed a memory leak when using Sentry Java SDK with Reactor Kafka. The leak occurs eve...

Opengraph URL: https://github.com/getsentry/sentry-java/issues/5051

X: @github

direct link

Domain: github.com

IPv4 address: 140.82.112.4


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Memory Leak Observed: SentryScheduleHook + Reactor Kafka Interaction","articleBody":"### Integration\n\nsentry-spring-boot-starter-jakarta\n\n### Java Version\n\n21\n\n### Version\n\n8.29.0\n\n### Steps to Reproduce\n\n## Summary\n\nWe observed a memory leak when using Sentry Java SDK with Reactor Kafka. The leak occurs even when idle (no messages), leading to OutOfMemoryError. The issue appears to stem from an interaction between the two libraries rather than either one alone.\n\n**Versions tested:** Sentry 8.29.0 and 8.30.0 (same behavior)\n\n## Environment\n\n- Java: OpenJDK 21.0.1 LTS\n- Spring Boot: 3.5.9\n- Reactor Kafka: 1.3.25\n- OS: macOS\n\n## Our Analysis\n\nBased on our investigation, we believe the issue arises from the following interaction:\n\n### The Mechanism\n\nReactor Kafka's `ConsumerEventLoop.PollEvent` reschedules itself infinitely on a **dedicated single-threaded scheduler**:\n\n```java\n// reactor-kafka ConsumerEventLoop.java:310-412\nclass PollEvent implements Runnable {\n    public void run() {\n        consumer.poll(pollTimeout);\n        if (isActive.get()) {\n            schedule();  // Reschedules itself infinitely\n        }\n    }\n    void schedule() {\n        eventScheduler.schedule(this);  // Triggers SentryScheduleHook\n    }\n}\n```\n\nEach `schedule()` call triggers `SentryScheduleHook.apply()`, which creates a forked scope with a parent reference:\n\n```java\n// SentryScheduleHook.java\npublic Runnable apply(Runnable runnable) {\n    final IScopes newScopes = Sentry.getCurrentScopes().forkedCurrentScope(\"spring.scheduleHook\");\n    return () -> { /* ... */ };\n}\n\n// Scopes.java:119 - each fork captures the parent\npublic IScopes forkedCurrentScope(String creator) {\n    return new Scopes(scope.clone(), isolationScope, globalScope, this, creator);\n    //                                                            ^^^^ parent reference\n}\n```\n\n**Result:** The dedicated scheduler thread is a permanent GC root, retaining an unbounded chain of `parentScopes`.\n\n### Why We Observed This Only with Reactor Kafka\n\nWe tested with `Flux.interval()` and other standard Reactor operations - no leak occurred. These use **pooled schedulers** where tasks complete and threads return to the pool, allowing scopes to be garbage collected.\n\nReactor Kafka differs by using a **dedicated single-threaded scheduler** (`Schedulers.newSingle()`) that:\n- Never terminates while the receiver is active\n- Reschedules the same `PollEvent` infinitely\n- Acts as a permanent GC root retaining all forked scopes\n\n### GC Root Path (from heap dump)\n\n```\nThread \"reactive-kafka-{groupId}-1\" [permanent GC root]\n  └─ SchedulerTask (82,915 instances after 17 min)\n     └─ ReentrantLock$NonfairSync\n        └─ io.sentry.Scope\n           └─ io.sentry.Scopes\n              └─ parentScopes → Scopes → parentScopes → ... (unbounded chain)\n```\n\n## Test Results\n\n| Scenario | Duration | ReentrantLock Growth | Rate/min | Heap Growth |\n|----------|----------|---------------------|----------|-------------|\n| App + Sentry 8.29.0 | 19 min | +84,349 | ~4,439 | +34 MB |\n| Minimal repro + Sentry | 17 min | +69,758 | ~4,103 | +30 MB |\n| App without Sentry (*) | 15 min | **0** | **0** | **0 MB** |\n\n(*) Manual GC performed before heap dumps to eliminate transient objects.\n\n## Reproduction\n\nA minimal Spring Boot application is provided in the attached ZIP. See `README.md` for setup instructions.\n\n```bash\n./run-test.sh  # Interactive test runner with 3 scenarios\n```\n\n## Workaround\n\nWe disable `SentryScheduleHook` after Sentry initializes (see `SentryWorkaroundConfiguration.kt`):\n\n```kotlin\n@EventListener(ApplicationReadyEvent::class)  // Must run AFTER Sentry's ApplicationRunner\nfun disableSentryScheduleHook() {\n    Schedulers.onScheduleHook(\"sentry\") { runnable -> runnable }\n}\n```\n\n**Trade-off:** Context propagation in scheduler tasks is disabled, but error reporting continues to work.\n\n---\n\n**Sentry Version:** 8.29.0, 8.30.0\n**Reactor Kafka Version:** 1.3.25\n**Spring Boot Version:** 3.5.9\n\n---\n\nWe hope this analysis is helpful. We may have misunderstood something, so please let us know if you need additional information or clarification. Happy to provide heap dumps or run additional tests if needed.\n\n[sentry-reactor-kafka-leak-reproduction.zip](https://github.com/user-attachments/files/24791402/sentry-reactor-kafka-leak-reproduction.zip)\n\n### Expected Result\n\n**Expected:** Memory should remain stable when the application is idle with no Kafka messages.\n\n### Actual Result\n\n**Actual:** Continuous growth of these objects (observable in heap dumps):\n- `java.util.concurrent.locks.ReentrantLock$NonfairSync`\n- `io.sentry.Scope` / `io.sentry.Scopes`\n- `io.sentry.PropagationContext`","author":{"url":"https://github.com/harrypennont","@type":"Person","name":"harrypennont"},"datePublished":"2026-01-22T09:47:09Z","url":"https://github.com/getsentry/sentry-java/issues/5051"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:c0dc25ea-a7f6-72d7-2140-290e4d2c01a8
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idE6DA:2F671E:728B6E:97269A:6B04C874
html-safe-nonce2516ab01e53c7e103d3584e85ace3bd436a87f0c519c19e4e1de5c9fde211346
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNkRBOjJGNjcxRTo3MjhCNkU6OTcyNjlBOjZCMDRDODc0IiwidmlzaXRvcl9pZCI6Ijg2MzQzMjU4NzY4MjMzNDUyNjgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmacf0c1a06d88916df951e9f77c5bb0a48a6ba5d29baa067dc126a806808a284c69
hovercard-subject-tagissue:3842110240
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/getsentry/sentry-java/5051/issue_layout
twitter:imagehttps://opengraph.githubassets.com/81146ba17b7f60abca7eec5aae619e14435668e17743751c870d29b487ba93e5/getsentry/sentry-java/issues/5051
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/81146ba17b7f60abca7eec5aae619e14435668e17743751c870d29b487ba93e5/getsentry/sentry-java/issues/5051
og:image:altIntegration sentry-spring-boot-starter-jakarta Java Version 21 Version 8.29.0 Steps to Reproduce Summary We observed a memory leak when using Sentry Java SDK with Reactor Kafka. The leak occurs eve...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameharrypennont
hostnamegithub.com
expected-hostnamegithub.com
None85dd75377eb77313206b8fc108bcee6a3a029286d94bf32bf9b4426e4d92e0c4
turbo-cache-controlno-preview
go-importgithub.com/getsentry/sentry-java git https://github.com/getsentry/sentry-java.git
octolytics-dimension-user_id1396951
octolytics-dimension-user_logingetsentry
octolytics-dimension-repository_id3368190
octolytics-dimension-repository_nwogetsentry/sentry-java
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id3368190
octolytics-dimension-repository_network_root_nwogetsentry/sentry-java
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release0d64fa748a2bab9a5b587a967ac4da1cfa8da6dd
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/getsentry/sentry-java/issues/5051#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgetsentry%2Fsentry-java%2Fissues%2F5051
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgetsentry%2Fsentry-java%2Fissues%2F5051
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=getsentry%2Fsentry-java
Reloadhttps://github.com/getsentry/sentry-java/issues/5051
Reloadhttps://github.com/getsentry/sentry-java/issues/5051
Reloadhttps://github.com/getsentry/sentry-java/issues/5051
getsentryhttps://github.com/getsentry
sentry-javahttps://github.com/getsentry/sentry-java
Codehttps://github.com/getsentry/sentry-java
Issues266 (266)https://github.com/getsentry/sentry-java/issues
Pull requests56 (56)https://github.com/getsentry/sentry-java/pulls
Discussionshttps://github.com/getsentry/sentry-java/discussions
Actionshttps://github.com/getsentry/sentry-java/actions
Projectshttps://github.com/getsentry/sentry-java/projects
Security and quality2 (2)https://github.com/getsentry/sentry-java/security
Insightshttps://github.com/getsentry/sentry-java/insights
https://github.com/getsentry/sentry-java
New issuehttps://github.com/login?return_to=https://github.com/getsentry/sentry-java/issues/5051
New issuehttps://github.com/login?return_to=https://github.com/getsentry/sentry-java/issues/5051
#5080https://github.com/getsentry/sentry-java/pull/5080
Memory Leak Observed: SentryScheduleHook + Reactor Kafka Interactionhttps://github.com/getsentry/sentry-java/issues/5051#top
#5080https://github.com/getsentry/sentry-java/pull/5080
Bughttps://github.com/getsentry/sentry-java/issues?q=state%3Aopen%20label%3A%22Bug%22
Javahttps://github.com/getsentry/sentry-java/issues?q=state%3Aopen%20label%3A%22Java%22
https://github.com/harrypennont
harrypennonthttps://github.com/harrypennont
on Jan 22, 2026https://github.com/getsentry/sentry-java/issues/5051#issue-3842110240
sentry-reactor-kafka-leak-reproduction.ziphttps://github.com/user-attachments/files/24791402/sentry-reactor-kafka-leak-reproduction.zip
harrypennonthttps://github.com/harrypennont
Bughttps://github.com/getsentry/sentry-java/issues?q=state%3Aopen%20label%3A%22Bug%22
Javahttps://github.com/getsentry/sentry-java/issues?q=state%3Aopen%20label%3A%22Java%22
on Jan 22, 2026https://github.com/getsentry/sentry-java/issues/5051#event-22211296760
getsantryhttps://github.com/apps/getsantry
Waiting for: Product Ownerhttps://github.com/getsentry/sentry-java/issues?q=state%3Aopen%20label%3A%22Waiting%20for%3A%20Product%20Owner%22
on Jan 22, 2026https://github.com/getsentry/sentry-java/issues/5051#event-22211297474
https://github.com/apps/linear
linearhttps://github.com/apps/linear
on Jan 22, 2026https://github.com/getsentry/sentry-java/issues/5051#issuecomment-3783479887
Linearhttps://linear.app
JAVA-287https://linear.app/getsentry/issue/JAVA-287/memory-leak-observed-sentryschedulehook-reactor-kafka-interaction
getsantryhttps://github.com/apps/getsantry
GitHub Issues with 👀 3https://github.com/orgs/getsentry/projects/227
on Jan 22, 2026https://github.com/getsentry/sentry-java/issues/5051#event-22211299198
getsantryhttps://github.com/apps/getsantry
GitHub Issues with 👀 3https://github.com/orgs/getsentry/projects/227
on Jan 22, 2026https://github.com/getsentry/sentry-java/issues/5051
Platform: Javahttps://github.com/getsentry/sentry-java/issues?q=state%3Aopen%20label%3A%22Platform%3A%20Java%22
on Jan 22, 2026https://github.com/getsentry/sentry-java/issues/5051#event-22211300238
https://github.com/adinauer
adinauerhttps://github.com/adinauer
on Feb 2, 2026https://github.com/getsentry/sentry-java/issues/5051#issuecomment-3833868560
getsantryhttps://github.com/apps/getsantry
Waiting for: Product Ownerhttps://github.com/getsentry/sentry-java/issues?q=state%3Aopen%20label%3A%22Waiting%20for%3A%20Product%20Owner%22
on Feb 2, 2026https://github.com/getsentry/sentry-java/issues/5051#event-22459016084
getsantryhttps://github.com/apps/getsantry
GitHub Issues with 👀 3https://github.com/orgs/getsentry/projects/227
on Feb 2, 2026https://github.com/getsentry/sentry-java/issues/5051
https://github.com/adinauer
adinauerhttps://github.com/adinauer
on Feb 6, 2026https://github.com/getsentry/sentry-java/issues/5051#issuecomment-3859712427
adinauerhttps://github.com/adinauer
completedhttps://github.com/getsentry/sentry-java/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#5080https://github.com/getsentry/sentry-java/pull/5080
on Feb 6, 2026https://github.com/getsentry/sentry-java/issues/5051#event-22587771173
https://github.com/harrypennont
harrypennonthttps://github.com/harrypennont
on Feb 6, 2026https://github.com/getsentry/sentry-java/issues/5051#issuecomment-3860228910
https://github.com/adinauer
adinauerhttps://github.com/adinauer
on Feb 6, 2026https://github.com/getsentry/sentry-java/issues/5051#issuecomment-3860485024
https://github.com/adinauer
adinauerhttps://github.com/adinauer
on Feb 9, 2026https://github.com/getsentry/sentry-java/issues/5051#issuecomment-3870914511
https://github.com/getsentry/sentry-java/releases/tag/8.32.0https://github.com/getsentry/sentry-java/releases/tag/8.32.0
https://github.com/harrypennont
harrypennonthttps://github.com/harrypennont
on Feb 10, 2026https://github.com/getsentry/sentry-java/issues/5051#issuecomment-3877434914
https://github.com/adinauer
adinauerhttps://github.com/adinauer
on Feb 11, 2026https://github.com/getsentry/sentry-java/issues/5051#issuecomment-3883028553
stephanie-andersonhttps://github.com/stephanie-anderson
Platform: Javahttps://github.com/getsentry/sentry-java/issues?q=state%3Aopen%20label%3A%22Platform%3A%20Java%22
on Mar 23, 2026https://github.com/getsentry/sentry-java/issues/5051#event-23809541155
Sign up for freehttps://github.com/signup?return_to=https://github.com/getsentry/sentry-java/issues/5051
Sign in to commenthttps://github.com/login?return_to=https://github.com/getsentry/sentry-java/issues/5051
Bughttps://github.com/getsentry/sentry-java/issues?q=state%3Aopen%20label%3A%22Bug%22
Javahttps://github.com/getsentry/sentry-java/issues?q=state%3Aopen%20label%3A%22Java%22
GitHub Issues with 👀 3https://github.com/orgs/getsentry/projects/227
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Response headers:
Servergithub.com
Content-Typetext/html; charset=utf-8
Cache-Controlmax-age=0, private, must-revalidate

Viewport: width=device-width


URLs of crawlers that visited me.