Summary
Main thread ANR caused by ReplayIntegration.resumeInternal -> AndroidConnectionStatusProvider.updateCache deadlocking on a ReentrantLock when the app returns to foreground. Disabling Replay (set both replay sample rates to 0.0) stops the ANR.
Environment
- sentry_flutter: (version in use)
- Flutter: 3.38.x stable
- Android: observed on Android 13+ devices
- Replay enabled with non-zero sample rates (session/onError)
Repro steps
- Start app with Replay enabled (non-zero replay.sessionSampleRate / replay.onErrorSampleRate).
- Send app to background for a while (OS may stop surfaces).
- Return to the app (launcher/task switch).
- ANR dialog appears; app is frozen/blank.
Expected
No ANR; Replay should not block the UI thread on foreground.
Actual
ANR; main thread is parked inside Replay while holding a lock. Another Replay thread is also waiting on the same lock.
Main thread (ANR) stack (excerpt)
main (waiting)
at jdk.internal.misc.Unsafe.park
at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquire
at java.util.concurrent.locks.ReentrantLock.lock
at io.sentry.util.AutoClosableReentrantLock.acquire
at io.sentry.android.core.internal.util.AndroidConnectionStatusProvider.updateCache
at io.sentry.android.core.internal.util.AndroidConnectionStatusProvider.getConnectionStatus
at io.sentry.android.replay.ReplayIntegration.resumeInternal
at io.sentry.android.replay.ReplayIntegration.resume
at io.sentry.android.core.LifecycleWatcher.startSession
...
Other Sentry thread (also waiting)
SentryExecutorServiceThreadFactory-0 (waiting)
at jdk.internal.misc.Unsafe.park
...
at io.sentry.util.AutoClosableReentrantLock.acquire
at io.sentry.android.replay.ReplayIntegration.resumeInternal
at io.sentry.android.replay.ReplayIntegration.onConnectionStatusChanged
...
Init snippet
await SentryFlutter.init((options) {
options.dsn = '<dsn>';
// Replay was enabled here (non-zero rates):
options.replay.sessionSampleRate = 1.0; // example
options.replay.onErrorSampleRate = 1.0;
options.enableAppHangTracking = true;
options.anrEnabled = true;
options.tracesSampleRate = 1.0;
options.profilesSampleRate = 1.0;
}, appRunner: appRunner);
Workaround
Set both Replay rates to 0.0 to disable Replay:
options.replay.sessionSampleRate = 0.0;
options.replay.onErrorSampleRate = 0.0;
With Replay disabled, the ANR disappears.
Request
Please investigate the Replay -> AndroidConnectionStatusProvider lock contention on resume/foreground that blocks the main thread, and provide a fix or guidance on safe configuration until patched.
Summary
Main thread ANR caused by ReplayIntegration.resumeInternal -> AndroidConnectionStatusProvider.updateCache deadlocking on a ReentrantLock when the app returns to foreground. Disabling Replay (set both replay sample rates to 0.0) stops the ANR.
Environment
Repro steps
Expected
No ANR; Replay should not block the UI thread on foreground.
Actual
ANR; main thread is parked inside Replay while holding a lock. Another Replay thread is also waiting on the same lock.
Main thread (ANR) stack (excerpt)
Other Sentry thread (also waiting)
Init snippet
Workaround
Set both Replay rates to 0.0 to disable Replay:
With Replay disabled, the ANR disappears.
Request
Please investigate the Replay -> AndroidConnectionStatusProvider lock contention on resume/foreground that blocks the main thread, and provide a fix or guidance on safe configuration until patched.