Skip to content
Open
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 @@

### Fixes

- Fix performance collector scheduling many tasks in a row ([#5524](https://github.com/getsentry/sentry-java/pull/5524))
- Session Replay: Fix `VerifyError` in Compose masking under DexGuard/R8 obfuscation ([#5507](https://github.com/getsentry/sentry-java/pull/5507))
- Session Replay: Fix Compose view masking not working on obfuscated/minified builds ([#5503](https://github.com/getsentry/sentry-java/pull/5503))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public final class DefaultCompositePerformanceCollector implements CompositePerf

private final @NotNull SentryOptions options;
private final @NotNull AtomicBoolean isStarted = new AtomicBoolean(false);
private long lastCollectionTimestamp = 0;

public DefaultCompositePerformanceCollector(final @NotNull SentryOptions options) {
this.options = Objects.requireNonNull(options, "The options object is required.");
Expand Down Expand Up @@ -112,16 +111,8 @@ public void run() {
new TimerTask() {
@Override
public void run() {
long now = System.currentTimeMillis();

@runningcode runningcode Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The issue is that scheduleAtFixedRate could schedule thousands of tasks in a row if the system goes in to deep sleep but then we guard against it using this System.currentTimeMillis() which isn't a monotonic clock meaning it could go forwards and then guard is broken allowing thousands of tasks to run.

// The timer is scheduled to run every 100ms on average. In case it takes longer,
// subsequent tasks are executed more quickly. If two tasks are scheduled to run in
// less than 10ms, the measurement that we collect is not meaningful, so we skip it
if (now - lastCollectionTimestamp <= 10) {
return;
}
timedOutTransactions.clear();

lastCollectionTimestamp = now;
final @NotNull PerformanceCollectionData tempData =
new PerformanceCollectionData(options.getDateProvider().now().nanoTimestamp());

Expand All @@ -147,7 +138,7 @@ public void run() {
}
}
};
timer.scheduleAtFixedRate(
timer.schedule(
timerTask,
TRANSACTION_COLLECTION_INTERVAL_MILLIS,
TRANSACTION_COLLECTION_INTERVAL_MILLIS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class DefaultCompositePerformanceCollectorTest {
val collector = fixture.getSut(null, null)
assertTrue(fixture.options.performanceCollectors.isEmpty())
collector.start(fixture.transaction1)
verify(fixture.mockTimer, never())!!.scheduleAtFixedRate(any(), any<Long>(), any())
verify(fixture.mockTimer, never())!!.schedule(any(), any<Long>(), any())
}

@Test
Expand All @@ -104,22 +104,22 @@ class DefaultCompositePerformanceCollectorTest {
fun `when start, timer is scheduled every 100 milliseconds`() {
val collector = fixture.getSut()
collector.start(fixture.transaction1)
verify(fixture.mockTimer)!!.scheduleAtFixedRate(any(), any<Long>(), eq(100))
verify(fixture.mockTimer)!!.schedule(any(), any<Long>(), eq(100))
}

@Test
fun `when start with a string, timer is scheduled every 100 milliseconds`() {
val collector = fixture.getSut()
collector.start(fixture.id1)
verify(fixture.mockTimer)!!.scheduleAtFixedRate(any(), any<Long>(), eq(100))
verify(fixture.mockTimer)!!.schedule(any(), any<Long>(), eq(100))
}

@Test
fun `when stop, timer is stopped`() {
val collector = fixture.getSut()
collector.start(fixture.transaction1)
collector.stop(fixture.transaction1)
verify(fixture.mockTimer)!!.scheduleAtFixedRate(any(), any<Long>(), eq(100))
verify(fixture.mockTimer)!!.schedule(any(), any<Long>(), eq(100))
verify(fixture.mockTimer)!!.cancel()
}

Expand All @@ -128,15 +128,15 @@ class DefaultCompositePerformanceCollectorTest {
val collector = fixture.getSut()
collector.start(fixture.id1)
collector.stop(fixture.id1)
verify(fixture.mockTimer)!!.scheduleAtFixedRate(any(), any<Long>(), eq(100))
verify(fixture.mockTimer)!!.schedule(any(), any<Long>(), eq(100))
verify(fixture.mockTimer)!!.cancel()
}

@Test
fun `stopping a not collected transaction return null`() {
val collector = fixture.getSut()
val data = collector.stop(fixture.transaction1)
verify(fixture.mockTimer, never())!!.scheduleAtFixedRate(any(), any<Long>(), eq(100))
verify(fixture.mockTimer, never())!!.schedule(any(), any<Long>(), eq(100))
verify(fixture.mockTimer, never())!!.cancel()
assertNull(data)
}
Expand All @@ -145,7 +145,7 @@ class DefaultCompositePerformanceCollectorTest {
fun `stopping a not collected id return null`() {
val collector = fixture.getSut()
val data = collector.stop(fixture.id1)
verify(fixture.mockTimer, never())!!.scheduleAtFixedRate(any(), any<Long>(), eq(100))
verify(fixture.mockTimer, never())!!.schedule(any(), any<Long>(), eq(100))
verify(fixture.mockTimer, never())!!.cancel()
assertNull(data)
}
Expand Down Expand Up @@ -316,7 +316,7 @@ class DefaultCompositePerformanceCollectorTest {
collector.close()

// Timer was canceled
verify(fixture.mockTimer)!!.scheduleAtFixedRate(any(), any<Long>(), eq(100))
verify(fixture.mockTimer)!!.schedule(any(), any<Long>(), eq(100))
verify(fixture.mockTimer)!!.cancel()

// Data was cleared
Expand Down
Loading