Skip to content

Commit bf10fcd

Browse files
ref(session): Clear the unhandled marker for any terminal status
update() only cleared hasNonTerminatingUnhandledError for Crashed, so an ANR arriving after a non-terminating unhandled error left the marker set on an Abnormal session and serialized it into previous_session.json. The marker only decides how an Ok session is finalized, so any explicit terminal status clears it now. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent ef7948b commit bf10fcd

3 files changed

Lines changed: 8 additions & 7 deletions

File tree

‎sentry/src/main/java/io/sentry/Session.java‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ public boolean hasNonTerminatingUnhandledError() {
213213
/**
214214
* Records that an active session experienced an unhandled error which did not terminate the
215215
* process, counting the error and advancing the session's sequence without ending it. On {@link
216-
* #end()} the session is finalized as {@link State#Unhandled} unless a crash escalated it to
217-
* {@link State#Crashed} first.
216+
* #end()} the session is finalized as {@link State#Unhandled} unless a terminal status such as
217+
* {@link State#Crashed} or {@link State#Abnormal} took over first.
218218
*
219219
* <p>Hybrid SDKs whose unhandled errors do not kill the process. Native Java/Android capture
220220
* should not call this.
@@ -310,8 +310,9 @@ public boolean update(
310310
boolean sessionHasBeenUpdated = false;
311311
if (status != null) {
312312
this.status = status;
313-
// a crash terminates the process, so it takes precedence over a non-terminating one.
314-
if (status == State.Crashed) {
313+
// the flag only decides how an Ok session is finalized, so an explicit terminal status
314+
// such as a crash or an ANR takes precedence over a non-terminating error.
315+
if (status != State.Ok) {
315316
hasNonTerminatingUnhandledError = false;
316317
}
317318
sessionHasBeenUpdated = true;

‎sentry/src/test/java/io/sentry/cache/EnvelopeCacheTest.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ class EnvelopeCacheTest {
373373
)
374374
assertEquals(State.Abnormal, updatedSession!!.status)
375375
assertEquals("abnormal_mechanism", updatedSession.abnormalMechanism)
376-
assertTrue(updatedSession.hasNonTerminatingUnhandledError())
376+
assertFalse(updatedSession.hasNonTerminatingUnhandledError())
377377
}
378378

379379
@Test

‎sentry/src/test/java/io/sentry/protocol/SessionSerializationTest.kt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ class SessionSerializationTest {
3939
/**
4040
* An unhandled session cannot be built by mutating [getSut]: the flag is only reachable through
4141
* [Session.recordNonTerminatingUnhandledError], which no-ops unless the session is still `Ok`,
42-
* and a crash would clear it again. Ending on a fixed timestamp keeps `seq` and `duration`
43-
* deterministic.
42+
* and a terminal status would clear it again. Ending on a fixed timestamp keeps `seq` and
43+
* `duration` deterministic.
4444
*/
4545
fun getUnhandledSut() =
4646
Session(

0 commit comments

Comments
 (0)