Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce timeout of AsyncHttpTransport to avoid ANR #2879

Merged
merged 2 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adinauer this change will also affect backend, hope that's fine

options
.getLogger()
.log(
Expand Down
10 changes: 10 additions & 0 deletions sentry/src/test/java/io/sentry/transport/AsyncHttpTransportTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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")
}
Expand Down
Loading