Repository navigation
Open
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 / updateSessionForDroppedEventNonTerminating) 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.
Verified (in tests)
InternalSentrySdkTestflaked with exactly this ordering. The test persisted the session, the delayed move renamedsession.json, and reading it back failed withFileNotFoundException.PreviousSessionFinalizerthen sent the moved session as an extra envelope. Fixed on the test side in test(android): Wait for the previous session move in InternalSentrySdkTest #6358.- Forcing
MovePreviousSession.run()to wait untilsession.jsonexists reproduces the failure every time. EnvelopeCache.storeInternalalready skips the move for a session thatpersistCurrentSessionwrote (isAlreadyPersisted/lastPersistedSessionId).EnvelopeCache.movePreviousSession(File, File), which the init-timeMovePreviousSessiontask calls, does not perform that check.
Hypothesis (medium confidence, not observed in production)
- 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
PreviousSessionFinalizerwhile 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.
Unknowns
- Whether hybrid SDKs call these APIs early enough in practice to land before the executor drains the init tasks.
- Whether other synchronous writers of
session.jsonshare the same window.
Related: #5959 (disk-persisted data racing during SDK re-init, a different window on the same files).
via no.
--
Activity
linear-code commentedon Oct 23, 2026
JAVA-792