Skip to content

Android: crash during sentry_close() on SDK re-init deadlocks (handler blocks in read(), close blocks in pthread_join) #2244

Closed

Description

@TonyDowney

Description

On Android, a crash that lands while the native SDK is being closed deadlocks the process instead of producing a crash report. The crashing thread blocks inside the signal handler in read(). The platform thread blocks in sentry_close() → pthread_join(). Neither returns: no tombstone, no Sentry event, the UI freezes, and Android reports an ANR 80 s later.

The close comes from a re-init: a Flutter engine was recreated in the same process, its Dart main() called SentryFlutter.init again, and SentryAndroid.init closed the previous Scopes, which closes the NDK integration.

Environment

  • sentry_flutter 9.30.0, which brings io.sentry:sentry-android 8.56.0 and its bundled libsentry.so
  • NDK integration on (the default)
  • Pixel 8 (Tensor G3, Mali GPU), Android 16
  • Flutter 3.47.3, profile build

Steps to reproduce

This needs a native crash at the moment the native SDK closes, so it is a race. We hit it once in two tries and not again in 28 more.

  1. A Flutter app that calls SentryFlutter.init in main(), with a plain FlutterActivity.
  2. Change a configuration that recreates the activity, for example the system navigation mode. The default FlutterActivity destroys its engine and creates a new one in the same process, so main() and SentryFlutter.init run a second time.
  3. The old engine's GPU teardown aborts on another thread in that window (FORTIFY: pthread_mutex_lock called on a destroyed mutex in the Mali Vulkan driver; that half is a Flutter bug, reported in [Impeller] SIGABRT in vkDestroyFramebuffer after long background dwell (cross-GPU: Mali + Adreno) flutter/flutter#191168).

Expected

The abort is captured, or at worst the process dies with a tombstone.

Actual

The process hangs. From the ANR trace (package path removed):

Platform thread, in the second init:

"main" prio=5 tid=1 Native
  #00 libc.so      syscall+32
  #01 libc.so      pthread_join+240
  #02 libsentry.so (???)
  #03 libsentry.so sentry_close+128
  at io.sentry.ndk.SentryNdk.shutdown(Native method)
  at io.sentry.ndk.SentryNdk.close(SentryNdk.java:61)
  at io.sentry.android.ndk.SentryNdk.close(SentryNdk.java:102)
  at io.sentry.android.core.NdkIntegration.close(NdkIntegration.java:90)
  at io.sentry.Scopes.close(Scopes.java:442)
  at io.sentry.Sentry.init(Sentry.java:344)
  at io.sentry.Sentry.init(Sentry.java:251)
  at io.sentry.android.core.SentryAndroid.init(SentryAndroid.java:103)
  at io.sentry.android.core.SentryAndroid.init(SentryAndroid.java:84)

The crashing thread, inside the signal handler:

"Thread-73" prio=5 tid=36 Native
  #00 libc.so          read+8
  #01 libsentry.so     (???)
  #02 libsentry.so     (???)
  #03 [vdso]
  #04 libc.so          __fortify_fatal+224
  #05 libc.so          HandleUsingDestroyedMutex+64
  #06 libc.so          pthread_mutex_lock+140
  #07 libGLES_mali.so  vulkan::device::remove_slot_data+32
  #08 libGLES_mali.so  vkDestroyRenderPass+72
  #09.. libflutter.so

A third thread waits on a mutex in sentry_add_breadcrumb:

"SentryExecutorServiceThreadFactory-0" daemon prio=5 tid=61 Native
  #00 libc.so      syscall+32
  #01 libc.so      __futex_wait_ex+132
  #02 libc.so      NonPI::MutexLockWithTimeout+528
  #03 libsentry.so sentry_add_breadcrumb+88
  at io.sentry.ndk.NativeScope.nativeAddBreadcrumb(Native method)
  at io.sentry.ndk.NativeScope.addBreadcrumb(NativeScope.java:68)
  at io.sentry.android.ndk.NdkScopeObserver.lambda$addBreadcrumb$1...

These are the only three threads in the dump with libsentry.so frames. The thread that sentry_close joins does not appear in the dump, so I cannot show what it was waiting on. My reading is that the handler on tid 36 waits for a reply over a pipe from a thread that sentry_close is shutting down, but that is inference.

Workaround

We stopped the engine re-creation on a configuration change, so SentryFlutter.init no longer runs twice in one process on that path. The window still exists for any app that re-initialises the SDK while another thread can crash.

Activity

  1. linear-code commented on Oct 23, 2026

    @linear-code
  2. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Oct 23, 2026
  3. added
    Bug
    on Oct 23, 2026
  4. jpnurmi commented on Oct 26, 2026

    @jpnurmi
    Collaborator

    Thanks for a detailed report!

  5. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    AndroidBug

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions