From 941ae4f35b6b98c4076bfc7a1423125627405436 Mon Sep 17 00:00:00 2001 From: Nelson Osacky Date: Wed, 18 Nov 2026 17:16:37 +0100 Subject: [PATCH 1/2] fix(ndk): Keep the interrupt when SentryNdk waits for native libraries SentryNdk.init and close wrap an InterruptedException in an IllegalStateException. They don't own the calling thread, so they now restore its interrupt flag first, for the code that does. Refs #5513 Refs JAVA-552 Co-Authored-By: Claude Opus 5.5 --- .../java/io/sentry/android/ndk/SentryNdk.java | 4 +++ .../io/sentry/android/ndk/SentryNdkTest.kt | 31 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/sentry-android-ndk/src/main/java/io/sentry/android/ndk/SentryNdk.java b/sentry-android-ndk/src/main/java/io/sentry/android/ndk/SentryNdk.java index e2339ca911d..2b638b29383 100644 --- a/sentry-android-ndk/src/main/java/io/sentry/android/ndk/SentryNdk.java +++ b/sentry-android-ndk/src/main/java/io/sentry/android/ndk/SentryNdk.java @@ -101,6 +101,8 @@ public static void init( throw new IllegalStateException("Timeout waiting for Sentry NDK library to load"); } } catch (InterruptedException e) { + // we don't own the calling thread, so keep its interrupt for the code that does + Thread.currentThread().interrupt(); throw new IllegalStateException( "Thread interrupted while waiting for NDK libs to be loaded", e); } @@ -116,6 +118,8 @@ public static void close() { throw new IllegalStateException("Timeout waiting for Sentry NDK library to load"); } } catch (InterruptedException e) { + // we don't own the calling thread, so keep its interrupt for the code that does + Thread.currentThread().interrupt(); throw new IllegalStateException( "Thread interrupted while waiting for NDK libs to be loaded", e); } diff --git a/sentry-android-ndk/src/test/java/io/sentry/android/ndk/SentryNdkTest.kt b/sentry-android-ndk/src/test/java/io/sentry/android/ndk/SentryNdkTest.kt index afa3d7061c6..e07a41c5061 100644 --- a/sentry-android-ndk/src/test/java/io/sentry/android/ndk/SentryNdkTest.kt +++ b/sentry-android-ndk/src/test/java/io/sentry/android/ndk/SentryNdkTest.kt @@ -3,6 +3,7 @@ package io.sentry.android.ndk import io.sentry.android.core.SentryAndroidOptions import io.sentry.ndk.NdkOptions import kotlin.test.assertEquals +import kotlin.test.assertFailsWith import kotlin.test.assertFalse import kotlin.test.assertNotNull import kotlin.test.assertTrue @@ -96,4 +97,34 @@ class SentryNdkTest { assertEquals(2000L, fixture.capturedOptions!!.appHangTimeoutMillis) } } + + @Test + fun `init keeps the interrupt when interrupted while waiting for the native libraries`() { + val options = + SentryAndroidOptions().apply { + dsn = "https://key@sentry.io/proj" + cacheDirPath = "/cache" + } + + // CountDownLatch.await checks the interrupt before the count, so this throws right away + Thread.currentThread().interrupt() + try { + assertFailsWith { SentryNdk.init(options) } + assertTrue(Thread.currentThread().isInterrupted) + } finally { + // don't leak the interrupt into other tests + Thread.interrupted() + } + } + + @Test + fun `close keeps the interrupt when interrupted while waiting for the native libraries`() { + Thread.currentThread().interrupt() + try { + assertFailsWith { SentryNdk.close() } + assertTrue(Thread.currentThread().isInterrupted) + } finally { + Thread.interrupted() + } + } } From 9f9c390fe6774dc712fc1ee83367015702c7bc18 Mon Sep 17 00:00:00 2001 From: Nelson Osacky Date: Wed, 18 Nov 2026 18:33:57 +0100 Subject: [PATCH 2/2] test(ndk): Remove the tests added for keeping the interrupt Refs #5513 Refs JAVA-552 Co-Authored-By: Claude Opus 5.5 --- .../io/sentry/android/ndk/SentryNdkTest.kt | 31 ------------------- 1 file changed, 31 deletions(-) diff --git a/sentry-android-ndk/src/test/java/io/sentry/android/ndk/SentryNdkTest.kt b/sentry-android-ndk/src/test/java/io/sentry/android/ndk/SentryNdkTest.kt index e07a41c5061..afa3d7061c6 100644 --- a/sentry-android-ndk/src/test/java/io/sentry/android/ndk/SentryNdkTest.kt +++ b/sentry-android-ndk/src/test/java/io/sentry/android/ndk/SentryNdkTest.kt @@ -3,7 +3,6 @@ package io.sentry.android.ndk import io.sentry.android.core.SentryAndroidOptions import io.sentry.ndk.NdkOptions import kotlin.test.assertEquals -import kotlin.test.assertFailsWith import kotlin.test.assertFalse import kotlin.test.assertNotNull import kotlin.test.assertTrue @@ -97,34 +96,4 @@ class SentryNdkTest { assertEquals(2000L, fixture.capturedOptions!!.appHangTimeoutMillis) } } - - @Test - fun `init keeps the interrupt when interrupted while waiting for the native libraries`() { - val options = - SentryAndroidOptions().apply { - dsn = "https://key@sentry.io/proj" - cacheDirPath = "/cache" - } - - // CountDownLatch.await checks the interrupt before the count, so this throws right away - Thread.currentThread().interrupt() - try { - assertFailsWith { SentryNdk.init(options) } - assertTrue(Thread.currentThread().isInterrupted) - } finally { - // don't leak the interrupt into other tests - Thread.interrupted() - } - } - - @Test - fun `close keeps the interrupt when interrupted while waiting for the native libraries`() { - Thread.currentThread().interrupt() - try { - assertFailsWith { SentryNdk.close() } - assertTrue(Thread.currentThread().isInterrupted) - } finally { - Thread.interrupted() - } - } }