Skip to content

Investigate startup race moving the live session file #6361

Open

Description

@sentry-junior

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)

  • 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 test(android): Wait for the previous session move in InternalSentrySdkTest #6358.
  • Forcing MovePreviousSession.run() to wait until session.json exists reproduces the failure every time.
  • 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.

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 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.

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.json share the same window.

Related: #5959 (disk-persisted data racing during SDK re-init, a different window on the same files).

via no.

--

View Junior Session [Sentry]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions