From 12a780d82c1727c338ee23e08115e3d676cfba2d Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Mon, 3 Aug 2026 15:56:27 +0200 Subject: [PATCH 1/2] fix(core): Restore directory processor interrupt flag Restore the interrupt status when the inter-envelope processing delay is interrupted so callers can observe the interruption after directory processing returns. Add regression coverage for the interrupted delay path. Fixes JAVA-666 Co-Authored-By: OpenCode --- CHANGELOG.md | 1 + .../java/io/sentry/DirectoryProcessor.java | 3 +++ .../java/io/sentry/DirectoryProcessorTest.kt | 23 +++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a79d7527bd0..d5c3f3a2392 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Fixes +- Restore the interrupt flag when cached envelope processing is interrupted between files ([#5884](https://github.com/getsentry/sentry-java/issues/5884)) - Prevent inflated cold app start when the OS spawns the process in the background (e.g. FCM push) on API 35+ ([#5841](https://github.com/getsentry/sentry-java/pull/5841), [#5880](https://github.com/getsentry/sentry-java/pull/5880)) - Preserve single-sample ANR profile chunks so profiles remain available on ANR events ([#5872](https://github.com/getsentry/sentry-java/pull/5872)) - Avoid a CPU busy-loop when recording discarded log or metric envelopes under rate limiting ([#5835](https://github.com/getsentry/sentry-java/pull/5835)) diff --git a/sentry/src/main/java/io/sentry/DirectoryProcessor.java b/sentry/src/main/java/io/sentry/DirectoryProcessor.java index 1bc277b18cd..3cfef0aea5f 100644 --- a/sentry/src/main/java/io/sentry/DirectoryProcessor.java +++ b/sentry/src/main/java/io/sentry/DirectoryProcessor.java @@ -94,6 +94,9 @@ public void processDirectory(final @NotNull File directory) { Thread.sleep(ENVELOPE_PROCESSING_DELAY); } } catch (Throwable e) { + if (e instanceof InterruptedException) { + Thread.currentThread().interrupt(); + } logger.log(SentryLevel.ERROR, e, "Failed processing '%s'", directory.getAbsolutePath()); } } diff --git a/sentry/src/test/java/io/sentry/DirectoryProcessorTest.kt b/sentry/src/test/java/io/sentry/DirectoryProcessorTest.kt index ca890f13f90..970a1a99bf6 100644 --- a/sentry/src/test/java/io/sentry/DirectoryProcessorTest.kt +++ b/sentry/src/test/java/io/sentry/DirectoryProcessorTest.kt @@ -1,5 +1,6 @@ package io.sentry +import com.google.common.truth.Truth.assertThat import io.sentry.hints.ApplyScopeData import io.sentry.hints.Enqueable import io.sentry.hints.Retryable @@ -135,6 +136,28 @@ class DirectoryProcessorTest { verify(fixture.scopes).captureEvent(any(), anyOrNull()) } + @Test + fun `when envelope processing delay is interrupted, restores interrupt flag`() { + getTempEnvelope("envelope-event-attachment.txt") + val sut = + object : DirectoryProcessor(fixture.scopes, fixture.logger, 500, 30) { + override fun processFile(file: File, hint: Hint) = Unit + + override fun isRelevantFileName(fileName: String): Boolean = true + } + + Thread.currentThread().interrupt() + val interruptFlagRestored = + try { + sut.processDirectory(file) + Thread.currentThread().isInterrupted + } finally { + Thread.interrupted() + } + + assertThat(interruptFlagRestored).isTrue() + } + private fun getTempEnvelope(fileName: String): String { val testFile = this::class.java.classLoader.getResource(fileName) val testFileBytes = testFile!!.readBytes() From 274350581039d91012c488d4bce843cab039e7e5 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Wed, 5 Aug 2026 13:09:15 +0200 Subject: [PATCH 2/2] fix(core): Catch directory processor interrupts separately Handle thread interruption as its own control path in DirectoryProcessor. Restore the interrupt flag and log the interruption at INFO so shutdown or cancellation does not look like an application error. Co-Authored-By: OpenCode --- sentry/src/main/java/io/sentry/DirectoryProcessor.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/sentry/src/main/java/io/sentry/DirectoryProcessor.java b/sentry/src/main/java/io/sentry/DirectoryProcessor.java index 3cfef0aea5f..17f65bb8c76 100644 --- a/sentry/src/main/java/io/sentry/DirectoryProcessor.java +++ b/sentry/src/main/java/io/sentry/DirectoryProcessor.java @@ -93,10 +93,14 @@ public void processDirectory(final @NotNull File directory) { // InterruptedException will be handled by the outer try-catch Thread.sleep(ENVELOPE_PROCESSING_DELAY); } + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + logger.log( + SentryLevel.INFO, + e, + "Thread interrupted during processing '%s'", + directory.getAbsolutePath()); } catch (Throwable e) { - if (e instanceof InterruptedException) { - Thread.currentThread().interrupt(); - } logger.log(SentryLevel.ERROR, e, "Failed processing '%s'", directory.getAbsolutePath()); } }