Skip to content

Commit 998c538

Browse files
0xadam-brownOpenCode
andauthored
fix(core): Restore directory processor interrupt flag (#5884)
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 <noreply@opencode.ai>
1 parent fb4dfe9 commit 998c538

3 files changed

Lines changed: 31 additions & 0 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Fixes
66

7+
- Restore the interrupt flag when cached envelope processing is interrupted between files ([#5884](https://github.com/getsentry/sentry-java/issues/5884))
78
- 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))
89
- Preserve single-sample ANR profile chunks so profiles remain available on ANR events ([#5872](https://github.com/getsentry/sentry-java/pull/5872))
910
- Avoid a CPU busy-loop when recording discarded log or metric envelopes under rate limiting ([#5835](https://github.com/getsentry/sentry-java/pull/5835))

‎sentry/src/main/java/io/sentry/DirectoryProcessor.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ public void processDirectory(final @NotNull File directory) {
9393
// InterruptedException will be handled by the outer try-catch
9494
Thread.sleep(ENVELOPE_PROCESSING_DELAY);
9595
}
96+
} catch (InterruptedException e) {
97+
Thread.currentThread().interrupt();
98+
logger.log(
99+
SentryLevel.INFO,
100+
e,
101+
"Thread interrupted during processing '%s'",
102+
directory.getAbsolutePath());
96103
} catch (Throwable e) {
97104
logger.log(SentryLevel.ERROR, e, "Failed processing '%s'", directory.getAbsolutePath());
98105
}

‎sentry/src/test/java/io/sentry/DirectoryProcessorTest.kt‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.sentry
22

3+
import com.google.common.truth.Truth.assertThat
34
import io.sentry.hints.ApplyScopeData
45
import io.sentry.hints.Enqueable
56
import io.sentry.hints.Retryable
@@ -135,6 +136,28 @@ class DirectoryProcessorTest {
135136
verify(fixture.scopes).captureEvent(any(), anyOrNull<Hint>())
136137
}
137138

139+
@Test
140+
fun `when envelope processing delay is interrupted, restores interrupt flag`() {
141+
getTempEnvelope("envelope-event-attachment.txt")
142+
val sut =
143+
object : DirectoryProcessor(fixture.scopes, fixture.logger, 500, 30) {
144+
override fun processFile(file: File, hint: Hint) = Unit
145+
146+
override fun isRelevantFileName(fileName: String): Boolean = true
147+
}
148+
149+
Thread.currentThread().interrupt()
150+
val interruptFlagRestored =
151+
try {
152+
sut.processDirectory(file)
153+
Thread.currentThread().isInterrupted
154+
} finally {
155+
Thread.interrupted()
156+
}
157+
158+
assertThat(interruptFlagRestored).isTrue()
159+
}
160+
138161
private fun getTempEnvelope(fileName: String): String {
139162
val testFile = this::class.java.classLoader.getResource(fileName)
140163
val testFileBytes = testFile!!.readBytes()

0 commit comments

Comments
 (0)