Title: Deadlock between ReplayIntegration.close() and connectivity callbacks blocks main thread (ANR) · Issue #5518 · getsentry/sentry-java · GitHub
Open Graph Title: Deadlock between ReplayIntegration.close() and connectivity callbacks blocks main thread (ANR) · Issue #5518 · getsentry/sentry-java
X Title: Deadlock between ReplayIntegration.close() and connectivity callbacks blocks main thread (ANR) · Issue #5518 · getsentry/sentry-java
Description: Integration sentry-android Build System Gradle AGP Version 8.6.0 Proguard Disabled Other Error Monitoring Solution No Version 8.41.3 Steps to Reproduce SentryAndroid.init with Session Replay enabled (e.g. sessionSampleRate = 1.0) — Repla...
Open Graph Description: Integration sentry-android Build System Gradle AGP Version 8.6.0 Proguard Disabled Other Error Monitoring Solution No Version 8.41.3 Steps to Reproduce SentryAndroid.init with Session Replay enable...
X Description: Integration sentry-android Build System Gradle AGP Version 8.6.0 Proguard Disabled Other Error Monitoring Solution No Version 8.41.3 Steps to Reproduce SentryAndroid.init with Session Replay enable...
Opengraph URL: https://github.com/getsentry/sentry-java/issues/5518
X: @github
Domain: github.com
IPv4 address: 140.82.112.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Deadlock between ReplayIntegration.close() and connectivity callbacks blocks main thread (ANR)","articleBody":"### Integration\n\nsentry-android\n\n### Build System\n\nGradle\n\n### AGP Version\n\n8.6.0\n\n### Proguard\n\nDisabled\n\n### Other Error Monitoring Solution\n\nNo\n\n### Version\n\n8.41.3\n\n### Steps to Reproduce\n\n1. `SentryAndroid.init` with Session Replay enabled (e.g. `sessionSampleRate = 1.0`) — ReplayIntegration registers as a connection status observer and `AndroidConnectionStatusProvider`\n registers a `ConnectivityManager` network callback.\n2. Call `Sentry.close()` from the main thread shortly after init (or whenever a connectivity notification is in flight — Android delivers the current network state immediately after\n callback registration, so closing soon after init hits this reliably).\n 3. Race: loop init→close with replay enabled on a loaded emulator; reproduces within ~30 cycles.\n\n### Expected Result\n\nSentry.close() completes and the SDK shuts down cleanly.\n\n### Actual Result\n\n`Sentry.close()` never returns — AB-BA deadlock between `ReplayIntegration.lifecycleLock` and `AndroidConnectionStatusProvider.lock`. When `close()` runs on the main thread this is a permanent\n main-thread block (ANR).\n\n - **Closing thread**: `ReplayIntegration.close()` holds lifecycleLock (`ReplayIntegration.kt:365`) → `removeConnectionStatusObserver()` waits on the provider lock\n (`AndroidConnectionStatusProvider.java:441`).\n - **ConnectivityThread**: `updateCacheAndNotifyObservers` holds the provider lock while notifying observers (`AndroidConnectionStatusProvider.java:274`) →\n `ReplayIntegration.onConnectionStatusChanged` → `resumeInternal()` waits on lifecycleLock (`ReplayIntegration.kt:220`).\n\n```\n \"main\" Waiting\n at io.sentry.android.core.internal.util.AndroidConnectionStatusProvider.removeConnectionStatusObserver(AndroidConnectionStatusProvider.java:441)\n at io.sentry.android.replay.ReplayIntegration.close(ReplayIntegration.kt:370)\n at io.sentry.Scopes.close(Scopes.java:439)\n at io.sentry.Sentry.close(Sentry.java:727)\n\n \"ConnectivityThread\" Waiting\n at io.sentry.android.replay.ReplayIntegration.resumeInternal(ReplayIntegration.kt:220)\n at io.sentry.android.replay.ReplayIntegration.onConnectionStatusChanged(ReplayIntegration.kt:393)\n at io.sentry.android.core.internal.util.AndroidConnectionStatusProvider$1.updateCacheAndNotifyObservers(AndroidConnectionStatusProvider.java:277)\n at io.sentry.android.core.internal.util.AndroidConnectionStatusProvider$1.onCapabilitiesChanged(AndroidConnectionStatusProvider.java:255)\n```\n\nFull thread dump attached: [sentry_replay_deadlock_trace.txt](https://github.com/user-attachments/files/28771417/sentry_replay_deadlock_trace.txt)\n\n### Impact\n - CI (ongoing): Recurring 30-minute job timeouts in getsentry/sentry-dart integration tests e.g.\n https://github.com/getsentry/sentry-dart/actions/runs/27229728938/job/80406349339\n - Production (very rare): Any app with replay enabled that calls `Sentry.close()` or re-inits the SDK at runtime can\n deadlock if a connectivity change lands in the window. When `close()` runs on the main thread the result is a permanent ANR caused by the SDK, and the ANR trace is effectively undiagnosable for users — just two parked threads inside io.sentry.*.\n - Not affected: apps that never close/re-init Sentry; backgrounding alone is safe (stop() never takes the provider lock).","author":{"url":"https://github.com/buenaflor","@type":"Person","name":"buenaflor"},"datePublished":"2026-06-09T21:26:41Z","url":"https://github.com/getsentry/sentry-java/issues/5518"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:efb3f19d-c437-7d1b-404d-3da3a66208bf |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C540:613C2:13CF71:1BC136:6B046F9A |
| html-safe-nonce | 5858aebeb38bcb6c26c56c4161597a9a52f487d42b53afb68dbd837fe6473f9f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNTQwOjYxM0MyOjEzQ0Y3MToxQkMxMzY6NkIwNDZGOUEiLCJ2aXNpdG9yX2lkIjoiNTc4NDQ1NjIwMDc5MjA3NjE4NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 1e6036a4a537502eb0e76b3949fdddc2264ba03554c5fcda9ca26d7fbfd21e40 |
| hovercard-subject-tag | issue:4625741394 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/getsentry/sentry-java/5518/issue_layout |
| twitter:image | https://opengraph.githubassets.com/762216001e920c0eaac7c7e450c512e0b97a9ddb9fb142c590f6fbeb77c14cca/getsentry/sentry-java/issues/5518 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/762216001e920c0eaac7c7e450c512e0b97a9ddb9fb142c590f6fbeb77c14cca/getsentry/sentry-java/issues/5518 |
| og:image:alt | Integration sentry-android Build System Gradle AGP Version 8.6.0 Proguard Disabled Other Error Monitoring Solution No Version 8.41.3 Steps to Reproduce SentryAndroid.init with Session Replay enable... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | buenaflor |
| hostname | github.com |
| expected-hostname | github.com |
| None | ae8802492f12d3ba4f6b0d814054e617a2a5616b6327bf8555c10cd5b0dc2a6f |
| turbo-cache-control | no-preview |
| go-import | github.com/getsentry/sentry-java git https://github.com/getsentry/sentry-java.git |
| octolytics-dimension-user_id | 1396951 |
| octolytics-dimension-user_login | getsentry |
| octolytics-dimension-repository_id | 3368190 |
| octolytics-dimension-repository_nwo | getsentry/sentry-java |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 3368190 |
| octolytics-dimension-repository_network_root_nwo | getsentry/sentry-java |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | cfb5f24c6e01d85f70804652a5107e5cac03a161 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width