Title: Investigate startup race moving the live session file · Issue #6361 · getsentry/sentry-java · GitHub
Open Graph Title: Investigate startup race moving the live session file · Issue #6361 · getsentry/sentry-java
X Title: Investigate startup race moving the live session file · Issue #6361 · getsentry/sentry-java
Description: Sentry.init puts MovePreviousSession on the options executor. That task renames session.json to previous_session.json. The non-terminating hybrid APIs (InternalSentrySdk.captureEnvelopeNonTerminating / updateSessionForDroppedEventNonTerm...
Open Graph Description: Sentry.init puts MovePreviousSession on the options executor. That task renames session.json to previous_session.json. The non-terminating hybrid APIs (InternalSentrySdk.captureEnvelopeNonTerminati...
X Description: Sentry.init puts MovePreviousSession on the options executor. That task renames session.json to previous_session.json. The non-terminating hybrid APIs (InternalSentrySdk.captureEnvelopeNonTerminati...
Opengraph URL: https://github.com/getsentry/sentry-java/issues/6361
X: @github
Domain: github.com
IPv4 address: 140.82.112.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Investigate startup race moving the live session file","articleBody":"`Sentry.init` puts [`MovePreviousSession`](https://github.com/getsentry/sentry-java/blob/main/sentry/src/main/java/io/sentry/MovePreviousSession.java) on the options executor. That task renames `session.json` to `previous_session.json`. The non-terminating hybrid APIs ([`InternalSentrySdk.captureEnvelopeNonTerminating` / `updateSessionForDroppedEventNonTerminating`](https://github.com/getsentry/sentry-java/blob/main/sentry-android-core/src/main/java/io/sentry/android/core/InternalSentrySdk.java)) write the live session to `session.json` synchronously on the caller's thread through `EnvelopeCache.persistCurrentSession`. If such a call happens before the executor runs the move, the move may treat the live session as the previous one.\n\n**Verified (in tests)**\n- `InternalSentrySdkTest` flaked with exactly this ordering. The test persisted the session, the delayed move renamed `session.json`, and reading it back failed with `FileNotFoundException`. `PreviousSessionFinalizer` then sent the moved session as an extra envelope. Fixed on the test side in #6358.\n- Forcing `MovePreviousSession.run()` to wait until `session.json` exists reproduces the failure every time.\n- `EnvelopeCache.storeInternal` already skips the move for a session that `persistCurrentSession` wrote (`isAlreadyPersisted` / `lastPersistedSessionId`). `EnvelopeCache.movePreviousSession(File, File)`, which the init-time `MovePreviousSession` task calls, does not perform that check.\n\n**Hypothesis (medium confidence, not observed in production)**\n- A hybrid SDK (React Native, Flutter, etc.) that reports an error through the non-terminating API right after init could have its live session moved, then ended and sent by `PreviousSessionFinalizer` while the scope keeps updating the same session. Possible results: a duplicate or split session, or a non-terminating unhandled-error marker that's lost if the process dies.\n\n**Unknowns**\n- Whether hybrid SDKs call these APIs early enough in practice to land before the executor drains the init tasks.\n- Whether other synchronous writers of `session.json` share the same window.\n\nRelated: #5959 (disk-persisted data racing during SDK re-init, a different window on the same files).\n\n\u003c!-- junior-request-attribution:start -->\nvia **no**.\n\u003c!-- junior-request-attribution:end -->\n\n\u003c!-- junior-session-footer:start -->\n\u003c!-- junior-conversation-id:slack%3AC089VFRB8N9%3A1792686024.928509 -->\n\n--\n\n[View Junior Session](https://junior-prod.sentry.dev/conversations/slack%3AC089VFRB8N9%3A1792686024.928509) [[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AC089VFRB8N9%3A1792686024.928509/?project=4510944073809921)\n\n\u003c!-- junior-session-footer:end -->","author":{"url":"https://github.com/apps/sentry-junior","@type":"Person","name":"sentry-junior"},"datePublished":"2026-10-23T07:43:55Z","url":"https://github.com/getsentry/sentry-java/issues/6361"}
| 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:1fe4fbfb-f2b7-2c60-6137-59edeaa29bd8 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A03C:32BBAA:169838:1FB5D0:6B0465EB |
| html-safe-nonce | fa3cdcac606210328ca25371438d450fae458ba503d4f629ab19cc9b6886d205 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMDNDOjMyQkJBQToxNjk4Mzg6MUZCNUQwOjZCMDQ2NUVCIiwidmlzaXRvcl9pZCI6IjU0MDY3NzQ2NjEwMjU2NTQyNTEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | aa3a822bd0a4fcfe4caf2627cef2a9af6437df50bc8d1e20296e6a91d8342e98 |
| hovercard-subject-tag | issue:5993961582 |
| 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/6361/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9c776871fdeca61d86694eac160384aaf02e84ebffe0a8d1a52407ea4b4693ff/getsentry/sentry-java/issues/6361 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9c776871fdeca61d86694eac160384aaf02e84ebffe0a8d1a52407ea4b4693ff/getsentry/sentry-java/issues/6361 |
| og:image:alt | Sentry.init puts MovePreviousSession on the options executor. That task renames session.json to previous_session.json. The non-terminating hybrid APIs (InternalSentrySdk.captureEnvelopeNonTerminati... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | sentry-junior[bot] |
| hostname | github.com |
| expected-hostname | github.com |
| None | 83e4c0e58c5162177f3c161c5fbad38527ae04c11ac14980f9f9d85ae2027b1f |
| 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 | ca4d07a7cef4e4b75f821dc25e7300d80c1450a9 |
| 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