Repository navigation
fix(android): Persist hard-crash envelopes to disk before the process exits - #6937
Conversation
Semver Impact of This PR⚪ None (no version bump detected) 📋 Changelog PreviewThis is how your changes will appear in the changelog.
🤖 This preview updates automatically when you update the PR. |
|
Small thing on the "matching iOS" part: iOS only takes the |
… exits A fatal JS error was captured through InternalSentrySdk.captureEnvelope, which only queues the envelope on the single-threaded transport executor. React Native then rethrows the error as JavascriptException, an ignored exception type, so UncaughtExceptionHandlerIntegration skips the disk flush and the process dies with the envelope still in memory. In release builds most fatal JS errors never reached Sentry. When hardCrashed is set, read the envelope, end the current session as crashed and attach it (the same session handling as InternalSentrySdk.captureEnvelope), delete the current-session file, and write the envelope to options.getEnvelopeDiskCache() on the calling thread. The next launch sends the cached file, which matches the iOS store path. Without a disk cache, or when the envelope cannot be read, the previous queued path runs. When the store itself fails, the repackaged envelope is queued instead so only one copy exists. Fixes #6918
Address review feedback on the hard-crash store path. The current-session file was deleted before the envelope was written to the disk cache. If the store failed, the envelope was only queued while the file was already gone, so the next launch could not report the session as abnormal. The file is now deleted only after storeEnvelope succeeds. Debuggable builds now skip the store path and capture directly, like the iOS #if DEBUG gate. In debug builds LogBox keeps the app alive, so the event would otherwise sit in the cache until the next launch. Two new tests cover both cases; both fail on the previous code.
dc4fb97 to
dd2cc62
Compare
|
Good point, thanks. Added the gate so now when the host app has |
📲 Install BuildsAndroid
|
📢 Type of change
📜 Description
When
hardCrashedis true,RNSentryModuleImpl.captureEnvelopenow writes the envelope tooptions.getEnvelopeDiskCache()on the calling thread instead of queueing it on the transport executor. It applies the same session handling asInternalSentrySdk.captureEnvelope(end the session as crashed, attach it, delete the current-session file). The next launch sends the cached file, which matches the iOSstorepath. Without a disk cache the old queued path runs, and if the store fails the envelope is queued instead.💡 Motivation and Context
InternalSentrySdk.captureEnvelopeonly submits the envelope to the single-threaded transport executor. React Native then rethrows the fatal asJavascriptException, which is an ignored exception type, so the native SDK skips the disk flush and the process dies with the envelope still in memory. In release builds most fatal JS errors never reached Sentry.Fixes #6918
💚 How did you test it?
Added
RNSentryCaptureEnvelopeTestwith five cases (sync store, crashed session attached, fallback when the store fails, no disk cache, non-fatal path). Three of them fail onmainand all pass with this change. All Android unit tests andyarn lint:androidpass.📝 Checklist
sendDefaultPIIis enabled.