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 flush timeout to 4s on Android to avoid ANRs #2858

Merged
merged 3 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -6,6 +6,7 @@

Breaking changes:
- Capture failed HTTP requests by default ([#2794](https://github.com/getsentry/sentry-java/pull/2794))
- Reduce flush timeout to 4s on Android to avoid ANRs ([#2858](https://github.com/getsentry/sentry-java/pull/2858))

### Fixes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
@SuppressWarnings("Convert2MethodRef") // older AGP versions do not support method references
final class AndroidOptionsInitializer {

static final long DEFAULT_FLUSH_TIMEOUT_MS = 4000;

static final String SENTRY_COMPOSE_GESTURE_INTEGRATION_CLASS_NAME =
"io.sentry.compose.gestures.ComposeGestureTargetLocator";

Expand Down Expand Up @@ -93,6 +95,9 @@ static void loadDefaultAndMetadataOptions(

options.setDateProvider(new SentryAndroidDateProvider());

// set a lower flush timeout on Android to avoid ANRs
options.setFlushTimeoutMillis(DEFAULT_FLUSH_TIMEOUT_MS);

ManifestMetadataReader.applyMetadata(context, options, buildInfoProvider);
initializeCacheDirs(context, options);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,20 @@ class AndroidOptionsInitializerTest {
assertTrue(innerLogger.get(loggerField) is AndroidLogger)
}

@Test
fun `flush timeout is set to Android specific default value`() {
fixture.initSut()
assertEquals(AndroidOptionsInitializer.DEFAULT_FLUSH_TIMEOUT_MS, fixture.sentryOptions.flushTimeoutMillis)
}

@Test
fun `flush timeout can be overridden`() {
fixture.initSut(configureOptions = {
flushTimeoutMillis = 1234
})
assertEquals(1234, fixture.sentryOptions.flushTimeoutMillis)
}

@Test
fun `AndroidEventProcessor added to processors list`() {
fixture.initSut()
Expand Down
Loading