File tree Expand file tree Collapse file tree 4 files changed +25
-1
lines changed
main/java/io/sentry/android/core
test/java/io/sentry/android/core
sentry/src/main/java/io/sentry/cache Expand file tree Collapse file tree 4 files changed +25
-1
lines changed Original file line number Diff line number Diff line change 66
77Breaking changes:
88- Capture failed HTTP requests by default ([ #2794 ] ( https://github.com/getsentry/sentry-java/pull/2794 ) )
9+ - Reduce flush timeout to 4s on Android to avoid ANRs ([ #2858 ] ( https://github.com/getsentry/sentry-java/pull/2858 ) )
910- Set ip_address to {{auto}} by default, even if sendDefaultPII is disabled ([ #2860 ] ( https://github.com/getsentry/sentry-java/pull/2860 ) )
1011 - Instead use the "Prevent Storing of IP Addresses" option in the "Security & Privacy" project settings on sentry.io
1112
Original file line number Diff line number Diff line change 4141@ SuppressWarnings ("Convert2MethodRef" ) // older AGP versions do not support method references
4242final class AndroidOptionsInitializer {
4343
44+ static final long DEFAULT_FLUSH_TIMEOUT_MS = 4000 ;
45+
4446 static final String SENTRY_COMPOSE_GESTURE_INTEGRATION_CLASS_NAME =
4547 "io.sentry.compose.gestures.ComposeGestureTargetLocator" ;
4648
@@ -93,6 +95,9 @@ static void loadDefaultAndMetadataOptions(
9395
9496 options .setDateProvider (new SentryAndroidDateProvider ());
9597
98+ // set a lower flush timeout on Android to avoid ANRs
99+ options .setFlushTimeoutMillis (DEFAULT_FLUSH_TIMEOUT_MS );
100+
96101 ManifestMetadataReader .applyMetadata (context , options , buildInfoProvider );
97102 initializeCacheDirs (context , options );
98103
Original file line number Diff line number Diff line change @@ -174,6 +174,20 @@ class AndroidOptionsInitializerTest {
174174 assertTrue(innerLogger.get(loggerField) is AndroidLogger )
175175 }
176176
177+ @Test
178+ fun `flush timeout is set to Android specific default value` () {
179+ fixture.initSut()
180+ assertEquals(AndroidOptionsInitializer .DEFAULT_FLUSH_TIMEOUT_MS , fixture.sentryOptions.flushTimeoutMillis)
181+ }
182+
183+ @Test
184+ fun `flush timeout can be overridden` () {
185+ fixture.initSut(configureOptions = {
186+ flushTimeoutMillis = 1234
187+ })
188+ assertEquals(1234 , fixture.sentryOptions.flushTimeoutMillis)
189+ }
190+
177191 @Test
178192 fun `AndroidEventProcessor added to processors list` () {
179193 fixture.initSut()
Original file line number Diff line number Diff line change @@ -67,6 +67,8 @@ public class EnvelopeCache extends CacheStrategy implements IEnvelopeCache {
6767
6868 public static final String STARTUP_CRASH_MARKER_FILE = "startup_crash" ;
6969
70+ private static final long SESSION_FLUSH_DISK_TIMEOUT_MS = 15000 ;
71+
7072 private final CountDownLatch previousSessionLatch ;
7173
7274 private final @ NotNull Map <SentryEnvelope , String > fileNameMap = new WeakHashMap <>();
@@ -429,7 +431,9 @@ public void discard(final @NotNull SentryEnvelope envelope) {
429431 /** Awaits until the previous session (if any) is flushed to its own file. */
430432 public boolean waitPreviousSessionFlush () {
431433 try {
432- return previousSessionLatch .await (options .getFlushTimeoutMillis (), TimeUnit .MILLISECONDS );
434+ // use fixed timeout instead of configurable options.getFlushTimeoutMillis() to ensure there's
435+ // enough time to flush the session to disk
436+ return previousSessionLatch .await (SESSION_FLUSH_DISK_TIMEOUT_MS , TimeUnit .MILLISECONDS );
433437 } catch (InterruptedException e ) {
434438 Thread .currentThread ().interrupt ();
435439 options .getLogger ().log (DEBUG , "Timed out waiting for previous session to flush." );
You can’t perform that action at this time.
0 commit comments