Skip to content

Commit 87e3ecb

Browse files
committed
Merge branch 'feat/7.0.0' into feat/user-default-ip
2 parents 0809e95 + 3838091 commit 87e3ecb

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
Breaking 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

sentry-android-core/src/main/java/io/sentry/android/core/AndroidOptionsInitializer.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
@SuppressWarnings("Convert2MethodRef") // older AGP versions do not support method references
4242
final 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

sentry-android-core/src/test/java/io/sentry/android/core/AndroidOptionsInitializerTest.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff 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()

sentry/src/main/java/io/sentry/cache/EnvelopeCache.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff 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.");

0 commit comments

Comments
 (0)