Skip to content

Commit c49c254

Browse files
romtsnclaude
andcommitted
Use shutdownNow() for replay executors in close() to avoid ANR
shutdown() calls awaitTermination() which blocks up to shutdownTimeoutMillis. Since close() can run on the main thread (via Sentry.close() from hybrid SDKs), this risks an ANR. shutdownNow() is non-blocking and sufficient at teardown. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 3b21f8f commit c49c254

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

sentry-android-replay/src/main/java/io/sentry/android/replay/ReplayIntegration.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,8 @@ public class ReplayIntegration(
380380
recorder?.close()
381381
recorder = null
382382
rootViewsSpy.close()
383-
replayExecutor.shutdown()
384-
persistingExecutor.shutdown()
383+
replayExecutor.gracefulShutdown()
384+
persistingExecutor.gracefulShutdown()
385385
lifecycle.currentState = CLOSED
386386
}
387387
}

sentry-android-replay/src/main/java/io/sentry/android/replay/util/ReplayExecutorService.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ internal class ReplayExecutorService(
5757
}
5858
}
5959
}
60+
61+
fun gracefulShutdown() {
62+
synchronized(this) {
63+
if (!isShutdown) {
64+
delegate.shutdown()
65+
}
66+
}
67+
}
6068
}
6169

6270
internal class ReplayRunnable(val taskName: String, delegate: Runnable) : Runnable by delegate

0 commit comments

Comments
 (0)