Skip to content

Commit 408aaa2

Browse files
committed
fix(anr): Align stack collection limit with queue capacity and avoid closing caller-owned stream
- Changed MAX_NUM_STACKS to match queue capacity (120 instead of 151) to prevent stack eviction - Removed try-with-resources in toStream to avoid closing the caller-owned OutputStream
1 parent 034445f commit 408aaa2

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

sentry-android-core/src/main/java/io/sentry/android/core/anr/AnrProfileManager.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,9 @@ public AnrStackTrace from(final byte[] source) throws IOException {
7373
public void toStream(
7474
final @NotNull AnrStackTrace value, final @NotNull OutputStream sink)
7575
throws IOException {
76-
try (final @NotNull DataOutputStream dos = new DataOutputStream(sink)) {
77-
value.serialize(dos);
78-
dos.flush();
79-
sink.flush();
80-
}
76+
final @NotNull DataOutputStream dos = new DataOutputStream(sink);
77+
value.serialize(dos);
78+
dos.flush();
8179
}
8280
});
8381
}

sentry-android-core/src/main/java/io/sentry/android/core/anr/AnrProfilingIntegration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class AnrProfilingIntegration
3333
public static final long POLLING_INTERVAL_MS = 66;
3434
private static final long THRESHOLD_SUSPICION_MS = 1000;
3535
public static final long THRESHOLD_ANR_MS = 4000;
36-
static final int MAX_NUM_STACKS = (int) (10_000 / POLLING_INTERVAL_MS);
36+
static final int MAX_NUM_STACKS = (int) ((THRESHOLD_ANR_MS / POLLING_INTERVAL_MS) * 2);
3737

3838
private final AtomicBoolean enabled = new AtomicBoolean(true);
3939
private final Runnable updater = () -> lastMainThreadExecutionTime = SystemClock.uptimeMillis();

0 commit comments

Comments
 (0)