From dcb31bee698655f6c03557c9c147987e24d13f6e Mon Sep 17 00:00:00 2001 From: Nelson Osacky Date: Wed, 18 Nov 2026 17:17:15 +0100 Subject: [PATCH 1/3] fix: Stop swallowing errors in three places the Throwable audit found QueueFile deleted its file when reading it ran out of memory, as if the file were corrupt. It now resets the file only for the IndexOutOfBoundsException that a corrupt file causes. Installation wrapped an OutOfMemoryError in a RuntimeException. It now wraps only the IOException from reading or writing the installation file. The Ktor client integration swallowed coroutine cancellation while reading the response body for a failed-request event. It now rethrows CancellationException and fatal errors. Refs #5513 Refs JAVA-552 Co-Authored-By: Claude Opus 5.5 --- .../main/java/io/sentry/android/core/Installation.java | 2 +- .../java/io/sentry/ktorClient/SentryKtorClientUtils.kt | 9 ++++++++- sentry/src/main/java/io/sentry/cache/tape/QueueFile.java | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/sentry-android-core/src/main/java/io/sentry/android/core/Installation.java b/sentry-android-core/src/main/java/io/sentry/android/core/Installation.java index fcd4406a5f8..34a5da4f57e 100644 --- a/sentry-android-core/src/main/java/io/sentry/android/core/Installation.java +++ b/sentry-android-core/src/main/java/io/sentry/android/core/Installation.java @@ -43,7 +43,7 @@ public static String id(final @NotNull Context context) throws RuntimeException return deviceId; } deviceId = readInstallationFile(installation); - } catch (Throwable e) { + } catch (IOException e) { throw new RuntimeException(e); } } diff --git a/sentry-ktor-client/src/main/java/io/sentry/ktorClient/SentryKtorClientUtils.kt b/sentry-ktor-client/src/main/java/io/sentry/ktorClient/SentryKtorClientUtils.kt index 4ab9310d6b1..09f40e9234c 100644 --- a/sentry-ktor-client/src/main/java/io/sentry/ktorClient/SentryKtorClientUtils.kt +++ b/sentry-ktor-client/src/main/java/io/sentry/ktorClient/SentryKtorClientUtils.kt @@ -17,9 +17,11 @@ import io.sentry.exception.ExceptionMechanismException import io.sentry.exception.SentryHttpClientException import io.sentry.protocol.Mechanism import io.sentry.util.CookieUtils +import io.sentry.util.ExceptionUtils import io.sentry.util.HttpUtils import io.sentry.util.UrlUtils import java.util.concurrent.TimeUnit +import kotlin.coroutines.cancellation.CancellationException internal object SentryKtorClientUtils { internal suspend fun captureClientError( @@ -52,7 +54,12 @@ internal object SentryKtorClientUtils { statusCode = response.status.value try { bodySize = response.bodyAsBytes().size.toLong() - } catch (_: Throwable) {} + } catch (e: CancellationException) { + throw e + } catch (@Suppress("TooGenericExceptionCaught") e: Throwable) { + // The HTTP engine can throw anything while reading the body. The body size is optional. + ExceptionUtils.rethrowIfFatal(e) + } } event.request = sentryRequest diff --git a/sentry/src/main/java/io/sentry/cache/tape/QueueFile.java b/sentry/src/main/java/io/sentry/cache/tape/QueueFile.java index 137f1cd9156..c93d19ebf75 100644 --- a/sentry/src/main/java/io/sentry/cache/tape/QueueFile.java +++ b/sentry/src/main/java/io/sentry/cache/tape/QueueFile.java @@ -379,7 +379,7 @@ boolean ringRead(long position, byte[] buffer, int offset, int count) throws IOE resetFile(); } catch (IOException e) { throw e; - } catch (Throwable e) { + } catch (IndexOutOfBoundsException e) { // most likely the file is corrupt, so we delete it and recreate, accepting data loss resetFile(); } From ad5b0c32e2413d124c8a902a3867361c2637b0be Mon Sep 17 00:00:00 2001 From: Nelson Osacky Date: Wed, 18 Nov 2026 17:32:37 +0100 Subject: [PATCH 2/3] changelog Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index be7899e2dd6..6c84e524bca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -96,6 +96,8 @@ ### Fixes - Set Apollo 3, 4, and 5 HTTP spans to `CANCELLED` instead of `INTERNAL_ERROR` when the request is cancelled ([#6284](https://github.com/getsentry/sentry-java/pull/6284)) +- The offline cache no longer deletes its queue file when it runs out of memory while reading it ([#6670](https://github.com/getsentry/sentry-java/pull/6670)) +- The Ktor client integration no longer swallows coroutine cancellation while reading the response body of a failed request ([#6670](https://github.com/getsentry/sentry-java/pull/6670)) - Preserve independent Netty read and write timeout events when exception singletons are reused. These exceptions now bypass event deduplication by default, so applications with multiple capture integrations may report the same timeout more than once. Use `SentryOptions.setIgnoredErrorsForDeduplication(...)` or `ignored-errors-for-deduplication` to customize or clear the default exclusions. ([#6465](https://github.com/getsentry/sentry-java/pull/6465)) - Prevent changes to reused tracing options from affecting spans and transactions after creation ([#6417](https://github.com/getsentry/sentry-java/pull/6417)) - Session Replay: Send Ktor client network request start and end times in milliseconds, so the requests line up with the replay ([#6619](https://github.com/getsentry/sentry-java/pull/6619)) From e828ee13821fb5008c276c6f41d6e964d3eba75c Mon Sep 17 00:00:00 2001 From: Nelson Osacky Date: Wed, 18 Nov 2026 18:35:23 +0100 Subject: [PATCH 3/3] changelog: Move the entry to #6665 Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c84e524bca..be7899e2dd6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -96,8 +96,6 @@ ### Fixes - Set Apollo 3, 4, and 5 HTTP spans to `CANCELLED` instead of `INTERNAL_ERROR` when the request is cancelled ([#6284](https://github.com/getsentry/sentry-java/pull/6284)) -- The offline cache no longer deletes its queue file when it runs out of memory while reading it ([#6670](https://github.com/getsentry/sentry-java/pull/6670)) -- The Ktor client integration no longer swallows coroutine cancellation while reading the response body of a failed request ([#6670](https://github.com/getsentry/sentry-java/pull/6670)) - Preserve independent Netty read and write timeout events when exception singletons are reused. These exceptions now bypass event deduplication by default, so applications with multiple capture integrations may report the same timeout more than once. Use `SentryOptions.setIgnoredErrorsForDeduplication(...)` or `ignored-errors-for-deduplication` to customize or clear the default exclusions. ([#6465](https://github.com/getsentry/sentry-java/pull/6465)) - Prevent changes to reused tracing options from affecting spans and transactions after creation ([#6417](https://github.com/getsentry/sentry-java/pull/6417)) - Session Replay: Send Ktor client network request start and end times in milliseconds, so the requests line up with the replay ([#6619](https://github.com/getsentry/sentry-java/pull/6619))