Skip to content

Commit 13ec6c7

Browse files
runningcodeclaude
andauthored
fix(android): Don't swallow interrupts while flushing a startup crash (#6568)
* fix(android): Don't swallow interrupts while flushing a startup crash After a startup crash, SendCachedEnvelopeIntegration blocks the thread that calls Sentry.init until the cached envelopes are sent. If that thread was interrupted, future.get() cleared the interrupt and the trailing catch (Throwable) swallowed it, so the caller never saw it. It also logged that cached events will not be sent, although the task keeps sending them. Catch InterruptedException next to the timeout, restore the interrupt and continue in the background. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * changelog --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent b98d31a commit 13ec6c7

3 files changed

Lines changed: 30 additions & 0 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444

4545
### Fixes
4646

47+
- Keep the interrupt of the thread that calls `Sentry.init` when it is interrupted while the SDK waits for cached events to be sent after a startup crash ([#6568](https://github.com/getsentry/sentry-java/pull/6568))
4748
- Capture scroll breadcrumbs for `LazyColumn`, `LazyRow`, lazy grids, and `Pager` on Jetpack Compose foundation 1.10+ ([#6548](https://github.com/getsentry/sentry-java/pull/6548))
4849
- Prevent the main thread from potentially hanging during app start or when returning to the foreground if Android is slow to register the SDK's network or telephony listeners. `Sentry.init`, Session Replay, and capturing events no longer wait for that registration ([#6537](https://github.com/getsentry/sentry-java/pull/6537))
4950
- Add opt-in support for matching GraphQL ignored error types against classification specifications via `sentry.graphql.enable-specification-error-type-filtering` ([#6092](https://github.com/getsentry/sentry-java/pull/6092))

‎sentry-android-core/src/main/java/io/sentry/android/core/SendCachedEnvelopeIntegration.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,13 @@ private void sendCachedEnvelopes(
157157
options
158158
.getLogger()
159159
.log(SentryLevel.DEBUG, "Synchronous send timed out, continuing in the background.");
160+
} catch (InterruptedException e) {
161+
// We don't own the calling thread, so keep its interrupt for the code that does
162+
Thread.currentThread().interrupt();
163+
options
164+
.getLogger()
165+
.log(
166+
SentryLevel.DEBUG, "Synchronous send interrupted, continuing in the background.");
160167
}
161168
}
162169
options.getLogger().log(SentryLevel.DEBUG, "SendCachedEnvelopeIntegration installed.");

‎sentry-android-core/src/test/java/io/sentry/android/core/SendCachedEnvelopeIntegrationTest.kt‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.sentry.android.core
22

3+
import com.google.common.truth.Truth.assertThat
34
import io.sentry.IConnectionStatusProvider
45
import io.sentry.IConnectionStatusProvider.ConnectionStatus
56
import io.sentry.ILogger
@@ -137,6 +138,27 @@ class SendCachedEnvelopeIntegrationTest {
137138
verify(fixture.sender).send()
138139
}
139140

141+
@Test
142+
fun `when interrupted while awaiting the task, keeps the interrupt and continues in the background`() {
143+
// the delay keeps the task running, so the wait for it sees the interrupt
144+
val sut = fixture.getSut(hasStartupCrashMarker = true, delaySend = 500)
145+
146+
Thread.currentThread().interrupt()
147+
try {
148+
sut.register(fixture.scopes, fixture.options)
149+
150+
assertThat(Thread.currentThread().isInterrupted).isTrue()
151+
} finally {
152+
// don't leak the interrupt into other tests
153+
Thread.interrupted()
154+
}
155+
verify(fixture.logger)
156+
.log(eq(DEBUG), eq("Synchronous send interrupted, continuing in the background."))
157+
158+
await.untilFalse(fixture.flag)
159+
verify(fixture.sender).send()
160+
}
161+
140162
@Test
141163
fun `registers for network connection changes`() {
142164
val sut =

0 commit comments

Comments
 (0)