Title: Session Replay: native SIGSEGV in `eglDestroySurface` (`libEGL_emulation`) when `SimpleVideoEncoder` releases its input surface on the Android emulator · Issue #6279 · getsentry/sentry-java · GitHub
Open Graph Title: Session Replay: native SIGSEGV in `eglDestroySurface` (`libEGL_emulation`) when `SimpleVideoEncoder` releases its input surface on the Android emulator · Issue #6279 · getsentry/sentry-java
X Title: Session Replay: native SIGSEGV in `eglDestroySurface` (`libEGL_emulation`) when `SimpleVideoEncoder` releases its input surface on the Android emulator · Issue #6279 · getsentry/sentry-java
Description: Integration sentry-android (Session Replay, sentry-android-replay) Build System Gradle AGP Version 9.3.1 Proguard Disabled (debug build) Other Error Monitoring Solution Firebase Crashlytics Version 8.47.0 (sentry-android-gradle-plugin 6....
Open Graph Description: Integration sentry-android (Session Replay, sentry-android-replay) Build System Gradle AGP Version 9.3.1 Proguard Disabled (debug build) Other Error Monitoring Solution Firebase Crashlytics Version...
X Description: Integration sentry-android (Session Replay, sentry-android-replay) Build System Gradle AGP Version 9.3.1 Proguard Disabled (debug build) Other Error Monitoring Solution Firebase Crashlytics Version...
Opengraph URL: https://github.com/getsentry/sentry-java/issues/6279
X: @github
Domain: github.com
IPv4 address: 140.82.112.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Session Replay: native SIGSEGV in `eglDestroySurface` (`libEGL_emulation`) when `SimpleVideoEncoder` releases its input surface on the Android emulator","articleBody":"### Integration\nsentry-android (Session Replay, `sentry-android-replay`)\n\n### Build System\nGradle\n\n### AGP Version\n9.3.1\n\n### Proguard\nDisabled (debug build)\n\n### Other Error Monitoring Solution\nFirebase Crashlytics\n\n### Version\n8.47.0 (sentry-android-gradle-plugin 6.14.0, sentry-native 0.15.2). The relevant code is unchanged in 8.61.0.\n\n### Steps to Reproduce\n\nThis is an intermittent race, not a deterministic repro.\n\n1. Enable Session Replay in session mode (`io.sentry.session-replay.session-sample-rate = 1.0`), default `PIXEL_COPY` screenshot strategy, NDK integration enabled.\n2. Run the app on an Android Emulator arm64 image: `system-images;android-37.1;google_apis_playstore_ps16k;arm64-v8a` (16 KB page size, Android 17, build `CP31.260623.012`), emulator 37.2.12.0, macOS / Apple Silicon host.\n3. Use the app normally while replay records segments (roughly one every 5 s).\n\nWe saw one crash after about 2 minutes (25 replay segments). An earlier 25-minute session (312 segments) did not crash.\n\n### Expected Result\n\nReleasing a replay segment's video encoder does not crash the process.\n\n### Actual Result\n\nNative crash on hwui's RenderThread while it destroys an EGL window surface. All frames are system/vendor code (no app frames):\n\n```\nSIGSEGV: Segfault (signalhandler, unhandled)\n\n\u003cunknown> /system/lib64/libutils.so\nandroid::RefBase::incStrongRequireStrong /system/lib64/libutils.so\nandroid::GraphicBuffer::from /system/lib64/libui.so\nandroid::Surface::hook_cancelBuffer /system/lib64/libgui.so\negl_window_surface_t::~egl_window_surface_t /vendor/lib64/egl/libEGL_emulation.so\negl_window_surface_t::~egl_window_surface_t /vendor/lib64/egl/libEGL_emulation.so\neglDestroySurface /vendor/lib64/egl/libEGL_emulation.so\n\u003cunknown> /system/lib64/libEGL.so\n\u003cunknown> x7 /system/lib64/libhwui.so\nandroid::Thread::_threadLoop /system/lib64/libutils.so\n\u003cunknown> /system/lib64/libutils.so\n\u003cunknown> x2 /apex/com.android.runtime/lib64/bionic/libc.so\n```\n\nThe crash time lines up with the end of the last recorded replay segment: the replay for that session ends in the same second the native crash was captured.\n\n**Why we think `SimpleVideoEncoder` is the source.** The `libhwui` frames are not symbolicated, so this comes from the shape of the stack plus the timing, not a frame-by-frame match:\n\n- `SimpleVideoEncoder.encode()` draws each frame with `surface.lockHardwareCanvas()` on non-Xiaomi/Motorola/Unisoc devices ([SimpleVideoEncoder.kt#L201 @ 8.61.0](https://github.com/getsentry/sentry-java/blob/8.61.0/sentry-android-replay/src/main/java/io/sentry/android/replay/video/SimpleVideoEncoder.kt#L201)). That gives the `MediaCodec` input `Surface` a hwui context, which owns an EGL window surface on the RenderThread.\n- `SimpleVideoEncoder.release()` calls `mediaCodec.release()` before `surface?.release()` ([L313-L330 @ 8.61.0](https://github.com/getsentry/sentry-java/blob/8.61.0/sentry-android-replay/src/main/java/io/sentry/android/replay/video/SimpleVideoEncoder.kt#L313-L330)). So the hwui context's EGL surface is destroyed after the codec, which is the BufferQueue consumer, has already been released.\n- The emulator's EGL driver keeps a dequeued buffer on its window surface and cancels it in `~egl_window_surface_t`. By then the buffer behind it has already been freed, so `GraphicBuffer::from` → `incStrongRequireStrong` dereferences a dead object.\n\nThe emulator's `libEGL_emulation` is arguably at fault for touching a freed buffer. But the replay SDK is the code that creates and tears down this surface every few seconds, and only on the emulator does that become a process crash.\n\n### Possible fixes\n\nEither of these, or both, would remove the window:\n\n1. In `SimpleVideoEncoder.release()`, release the input `Surface` (which destroys its hwui context and EGL surface) **before** `mediaCodec.release()`, after `drainCodec(true)` / `mediaCodec.stop()`.\n2. Use `surface.lockCanvas(null)` instead of `lockHardwareCanvas()` on emulators, as is already done for Xiaomi, Motorola, and Unisoc. For example, check `Build.HARDWARE` for `ranchu` or `goldfish`, or `Build.FINGERPRINT` starting with `generic`/`google/sdk_gphone`.\n\nWe can test a patched build on the same emulator image if that helps.\n","author":{"url":"https://github.com/taziz23","@type":"Person","name":"taziz23"},"datePublished":"2026-10-19T00:28:30Z","url":"https://github.com/getsentry/sentry-java/issues/6279"}
| 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:326f541c-a2b9-b0b2-12bd-432b93be37fe |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8622:45E1A:1A946B:24E4D1:6B0466DB |
| html-safe-nonce | 4502856f7c110da058ccf10492faf50a8ec82b209189201c24abdf74996d9227 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NjIyOjQ1RTFBOjFBOTQ2QjoyNEU0RDE6NkIwNDY2REIiLCJ2aXNpdG9yX2lkIjoiMjM1MDg0MDYxMDI3NTIyMzI1OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | ae296c59764bc9cab04a183c5ecbe5ec1a993f7282dce94e8fcecfb256a2001a |
| hovercard-subject-tag | issue:5915754679 |
| 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/6279/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b9fac82240a7b94ea8f73ec95ab1d9e3b331a3432296568c0b90595279481176/getsentry/sentry-java/issues/6279 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b9fac82240a7b94ea8f73ec95ab1d9e3b331a3432296568c0b90595279481176/getsentry/sentry-java/issues/6279 |
| og:image:alt | Integration sentry-android (Session Replay, sentry-android-replay) Build System Gradle AGP Version 9.3.1 Proguard Disabled (debug build) Other Error Monitoring Solution Firebase Crashlytics Version... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | taziz23 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 83e4c0e58c5162177f3c161c5fbad38527ae04c11ac14980f9f9d85ae2027b1f |
| 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 | ca4d07a7cef4e4b75f821dc25e7300d80c1450a9 |
| 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