Skip to content

Commit 1f490e4

Browse files
committed
reset crashedLastRun in PreviousSessionFinalizer and add test-case
1 parent 0d2b7cd commit 1f490e4

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

sentry/src/main/java/io/sentry/PreviousSessionFinalizer.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,10 @@ public void run() {
9292
if (session.getStatus() == Session.State.Crashed) {
9393
// this means the session was already updated from tombstone data and there is no need
9494
// to consider the crash-marker file from the Native SDK. However, we can use this to
95-
// set crashedLastRun.
96-
SentryCrashLastRunState.getInstance().setCrashedLastRun(true);
95+
// reset crashedLastRun.
96+
final @NotNull SentryCrashLastRunState crashLastRunState = SentryCrashLastRunState.getInstance();
97+
crashLastRunState.reset();
98+
crashLastRunState.setCrashedLastRun(true);
9799
} else if (crashMarkerFile.exists()) {
98100
// this means that the Native SDK is solely responsible for Native crashes and we must
99101
// update the session state and timestamp.

sentry/src/test/java/io/sentry/PreviousSessionFinalizerTest.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,23 @@ class PreviousSessionFinalizerTest {
237237
assertTrue(SentryCrashLastRunState.getInstance().isCrashedLastRun(null, false)!!)
238238
}
239239

240+
@Test
241+
fun `when previous session is already crashed and SessionStart was processed and no native crash marker exists, crashedLastRun is still true`() {
242+
// Create a session that is already in Crashed state (simulating tombstone integration)
243+
val crashedSession =
244+
Session(null, null, null, "io.sentry.sample@1.0").apply { update(Crashed, null, true) }
245+
246+
val finalizer = fixture.getSut(tmpDir, session = crashedSession)
247+
248+
// If the EnvelopeCache stored a SessionStart and no native crash marker was present then crashedLastRun would be false
249+
SentryCrashLastRunState.getInstance().setCrashedLastRun(false)
250+
251+
finalizer.run()
252+
253+
// the finalizer must be aware that this could have happened before and reset the crashedLastRun to true
254+
assertTrue(SentryCrashLastRunState.getInstance().isCrashedLastRun(null, false)!!)
255+
}
256+
240257
@Test
241258
fun `when native crash marker exists but session is not crashed, does not set crashedLastRun`() {
242259
// Session is not crashed, but native crash marker exists

0 commit comments

Comments
 (0)