Title: refactor(replay): Consider thread confinement for lifecycle state to eliminate lifecycleLock · Issue #5847 · getsentry/sentry-java · GitHub
Open Graph Title: refactor(replay): Consider thread confinement for lifecycle state to eliminate lifecycleLock · Issue #5847 · getsentry/sentry-java
X Title: refactor(replay): Consider thread confinement for lifecycle state to eliminate lifecycleLock · Issue #5847 · getsentry/sentry-java
Description: Context ReplayIntegration uses lifecycleLock to synchronize lifecycle state transitions (start, stop, pause, close, checkCanRecord). This has led to recurring deadlocks when the lock and the single-threaded replay executor wait on each o...
Open Graph Description: Context ReplayIntegration uses lifecycleLock to synchronize lifecycle state transitions (start, stop, pause, close, checkCanRecord). This has led to recurring deadlocks when the lock and the single...
X Description: Context ReplayIntegration uses lifecycleLock to synchronize lifecycle state transitions (start, stop, pause, close, checkCanRecord). This has led to recurring deadlocks when the lock and the single...
Opengraph URL: https://github.com/getsentry/sentry-java/issues/5847
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"refactor(replay): Consider thread confinement for lifecycle state to eliminate lifecycleLock","articleBody":"## Context\n\n`ReplayIntegration` uses `lifecycleLock` to synchronize lifecycle state transitions (`start`, `stop`, `pause`, `close`, `checkCanRecord`). This has led to recurring deadlocks when the lock and the single-threaded replay executor wait on each other:\n\n- #4788 — `checkCanRecord` running on executor, blocking on `lifecycleLock`\n- #5837 — same issue via PixelCopy callback path, plus `close()` holding lock during `awaitTermination`\n\nWith plans to expose `start`/`stop`/`resume`/`pause` as public API for manual control, users could call from any thread, making lock-ordering issues harder to reason about over time.\n\n## Proposal\n\nConfine all lifecycle state mutations to a single thread (main looper or a dedicated `HandlerThread`). Public methods post to that handler and return — callers don't need to know the execution context. The replay executor stays for heavy work (encoding, caching) but never touches lifecycle state.\n\nThis eliminates `lifecycleLock` entirely. No lock → no lock ordering → no deadlock class of bugs.\n\nAndroid's own lifecycle works this way: `finish()` can be called from any thread, but the state transition happens on main.\n\n### Open question\n\nWhether any caller needs synchronous confirmation that the operation completed. If `stop()` must guarantee \"replay is stopped when I return,\" confinement needs `post + await`. For replay lifecycle ops this likely isn't needed.\n\n## References\n\n- PR #5837 review discussion: https://github.com/getsentry/sentry-java/pull/5837#discussion_r3658486750","author":{"url":"https://github.com/romtsn","@type":"Person","name":"romtsn"},"datePublished":"2026-07-28T08:09:24Z","url":"https://github.com/getsentry/sentry-java/issues/5847"}
| 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:140080cf-8d8f-cd3a-1da8-323028a2293e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8780:3C07AF:6320B0:8868C2:6B047585 |
| html-safe-nonce | 55773ddf3ea49259d23db5ccde9762155edfdc0b7ac1a4edfe857c72b65780b9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NzgwOjNDMDdBRjo2MzIwQjA6ODg2OEMyOjZCMDQ3NTg1IiwidmlzaXRvcl9pZCI6Ijg2NzI2NjIxODc5NzE3MzY5NjUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 36d6089611e74f6ddb3da6bcc9f054840f28acb9af942c2c34dc5dbc53169003 |
| hovercard-subject-tag | issue:4996407218 |
| 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/5847/issue_layout |
| twitter:image | https://opengraph.githubassets.com/51a63ef1d153d23ac2315bcf791350056fbea10519c02165d829deb57e9ab8f8/getsentry/sentry-java/issues/5847 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/51a63ef1d153d23ac2315bcf791350056fbea10519c02165d829deb57e9ab8f8/getsentry/sentry-java/issues/5847 |
| og:image:alt | Context ReplayIntegration uses lifecycleLock to synchronize lifecycle state transitions (start, stop, pause, close, checkCanRecord). This has led to recurring deadlocks when the lock and the single... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | romtsn |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9c099f1b85def81ca352464c276510dfef32deaf3c305404e65b8d270284a58b |
| 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 | cf73f57448d52b3a7b619195e182b33d3b3454ca |
| 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