Title: Make SDK re-init cheap: avoid full-timeout executor close and duplicate thread sets · Issue #5715 · getsentry/sentry-java · GitHub
Open Graph Title: Make SDK re-init cheap: avoid full-timeout executor close and duplicate thread sets · Issue #5715 · getsentry/sentry-java
X Title: Make SDK re-init cheap: avoid full-timeout executor close and duplicate thread sets · Issue #5715 · getsentry/sentry-java
Description: Problem Customers initialize Sentry twice at startup (minimal init early to catch crashes, full init once async config is available — does exactly this). A customer cold-start trace (Galaxy A14 / API 34, TTID 1723 ms, method-level tracin...
Open Graph Description: Problem Customers initialize Sentry twice at startup (minimal init early to catch crashes, full init once async config is available — does exactly this). A customer cold-start trace (Galaxy A14 / A...
X Description: Problem Customers initialize Sentry twice at startup (minimal init early to catch crashes, full init once async config is available — does exactly this). A customer cold-start trace (Galaxy A14 / A...
Opengraph URL: https://github.com/getsentry/sentry-java/issues/5715
X: @github
Domain: github.com
IPv4 address: 140.82.113.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Make SDK re-init cheap: avoid full-timeout executor close and duplicate thread sets","articleBody":"## Problem\n\nCustomers initialize Sentry twice at startup (minimal init early to catch crashes, full init once async config is available — does exactly this). A customer cold-start trace (Galaxy A14 / API 34, TTID 1723 ms, method-level tracing) shows re-init is expensive:\n\n* `io.sentry.Sentry#init` runs twice: main thread @396 ms (16.7 ms) and a coroutine thread @587 ms (47.7 ms).\n* The re-init triggers **two** `io.sentry.SentryExecutorService#close` **calls that each block for the full 2000 ms** (`shutdownTimeoutMillis` default) — `awaitTermination` never completes, likely because the old executor queue is stuffed with scope-persistence work (or a task never terminates). Both ran on old `SentryExecutorS` threads, so no main-thread block here, but two threads spin for 2 s and any work queued behind them is lost/delayed.\n* The second init spawns a complete duplicate thread set (2× transport `SentryAsyncConn`, 2× frame-metrics `etricsCollector`, 3× `SentryExecutorS` observed).\n\n## Proposal (investigate)\n\n* Find out why `close` hits the full timeout (long-running queued task? persistence backlog? non-interruptible IO) — `Scopes.close` → `SentryOptions`/`SentryExecutorService.close(shutdownTimeoutMillis)`.\n* Fast-close path for the re-init case: drain-or-abandon semantics instead of a blocking `awaitTermination(2000)` (crash-relevant tasks excepted).\n* Investigate reusing executor/transport/collector threads across re-init when compatible options allow, instead of tearing down + respawning the world.\n* Consider documenting/supporting the \"init twice\" pattern explicitly (relates to `InitUtil.shouldInit` priorities and `forceInit`).\n\n## Notes\n\n* Evidence: customer trace `median.perfetto-trace`, analysis scratchpad `median.perfetto-trace_analysis_v2.md`. The macrobenchmark (getsentry/sentry-java#5679) won't catch this — the sample app inits once.","author":{"url":"https://github.com/runningcode","@type":"Person","name":"runningcode"},"datePublished":"2026-07-03T10:12:51Z","url":"https://github.com/getsentry/sentry-java/issues/5715"}
| react-profiling | 0 |
| react-import-map | react,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-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:3d8f29c4-397d-57fe-3898-2f1f6b72a8c7 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 82D4:3CEE1E:422469:5DB675:6B0470A1 |
| html-safe-nonce | bae15e11e1f1864be1a001d85e1fbd91f997a5372dacfb56084d340b7b13e106 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MkQ0OjNDRUUxRTo0MjI0Njk6NURCNjc1OjZCMDQ3MEExIiwidmlzaXRvcl9pZCI6IjMzNDMyMzk0NTU5NTA3OTQ5MTMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 3fc1178a38bc74f62b48e1fac15509a8aa977e76ec41d007a745116178fc36d6 |
| hovercard-subject-tag | issue:4802586201 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/getsentry/sentry-java/5715/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6adc4706972506a17a9d8cdfdcdd2c2b8c0eecb0f4a9cbfadcacfd3efecb10b2/getsentry/sentry-java/issues/5715 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6adc4706972506a17a9d8cdfdcdd2c2b8c0eecb0f4a9cbfadcacfd3efecb10b2/getsentry/sentry-java/issues/5715 |
| og:image:alt | Problem Customers initialize Sentry twice at startup (minimal init early to catch crashes, full init once async config is available — does exactly this). A customer cold-start trace (Galaxy A14 / A... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | runningcode |
| hostname | github.com |
| expected-hostname | github.com |
| None | ae8802492f12d3ba4f6b0d814054e617a2a5616b6327bf8555c10cd5b0dc2a6f |
| turbo-cache-control | no-preview |
| go-import | github.com/getsentry/sentry-java git https://github.com/getsentry/sentry-java.git |
| octolytics-dimension-user_id | 1396951 |
| octolytics-dimension-user_login | getsentry |
| octolytics-dimension-repository_id | 3368190 |
| octolytics-dimension-repository_nwo | getsentry/sentry-java |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 3368190 |
| octolytics-dimension-repository_network_root_nwo | getsentry/sentry-java |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | cfb5f24c6e01d85f70804652a5107e5cac03a161 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width