From ed58b1708eff8120b35171629aada181a3efdc51 Mon Sep 17 00:00:00 2001 From: stefanosiano Date: Thu, 3 Aug 2023 12:11:47 +0200 Subject: [PATCH 1/2] reduced timeout of AsyncHttpTransport close to flushTimeoutMillis (default 4s in Android and 15s in Java) to avoid ANRs in Android --- .../java/io/sentry/transport/AsyncHttpTransport.java | 2 +- .../java/io/sentry/transport/AsyncHttpTransportTest.kt | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/sentry/src/main/java/io/sentry/transport/AsyncHttpTransport.java b/sentry/src/main/java/io/sentry/transport/AsyncHttpTransport.java index cbd5494726..d750b96c7c 100644 --- a/sentry/src/main/java/io/sentry/transport/AsyncHttpTransport.java +++ b/sentry/src/main/java/io/sentry/transport/AsyncHttpTransport.java @@ -140,7 +140,7 @@ public void close() throws IOException { executor.shutdown(); options.getLogger().log(SentryLevel.DEBUG, "Shutting down"); try { - if (!executor.awaitTermination(1, TimeUnit.MINUTES)) { + if (!executor.awaitTermination(options.getFlushTimeoutMillis(), TimeUnit.MILLISECONDS)) { options .getLogger() .log( diff --git a/sentry/src/test/java/io/sentry/transport/AsyncHttpTransportTest.kt b/sentry/src/test/java/io/sentry/transport/AsyncHttpTransportTest.kt index ce59db5025..20f2ff6979 100644 --- a/sentry/src/test/java/io/sentry/transport/AsyncHttpTransportTest.kt +++ b/sentry/src/test/java/io/sentry/transport/AsyncHttpTransportTest.kt @@ -25,6 +25,7 @@ import org.mockito.kotlin.verify import org.mockito.kotlin.whenever import java.io.IOException import java.util.Date +import java.util.concurrent.TimeUnit import kotlin.test.Test import kotlin.test.assertEquals @@ -321,6 +322,15 @@ class AsyncHttpTransportTest { ) } + @Test + fun `close uses flushTimeoutMillis option to schedule termination`() { + fixture.sentryOptions.flushTimeoutMillis = 123 + val sut = fixture.getSUT() + sut.close() + + verify(fixture.executor).awaitTermination(eq(123), eq(TimeUnit.MILLISECONDS)) + } + private fun createSession(): Session { return Session("123", User(), "env", "release") } From 9fb4dd6bd722aa29cb0324228ce80ef47fc3e80b Mon Sep 17 00:00:00 2001 From: stefanosiano Date: Thu, 3 Aug 2023 12:18:46 +0200 Subject: [PATCH 2/2] updated changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ebb102f788..d4b03cd492 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ Breaking changes: - Reduce flush timeout to 4s on Android to avoid ANRs ([#2858](https://github.com/getsentry/sentry-java/pull/2858)) - Set ip_address to {{auto}} by default, even if sendDefaultPII is disabled ([#2860](https://github.com/getsentry/sentry-java/pull/2860)) - Instead use the "Prevent Storing of IP Addresses" option in the "Security & Privacy" project settings on sentry.io +- Reduce timeout of AsyncHttpTransport to avoid ANR ([#2879](https://github.com/getsentry/sentry-java/pull/2879)) ### Fixes