Skip to content

fix: drop app-start transaction when deadline timer fires doze-delayed#5755

Open
mvanhorn wants to merge 3 commits into
getsentry:mainfrom
mvanhorn:fix/5752-doze-skewed-app-start-transaction
Open

fix: drop app-start transaction when deadline timer fires doze-delayed#5755
mvanhorn wants to merge 3 commits into
getsentry:mainfrom
mvanhorn:fix/5752-doze-skewed-app-start-transaction

Conversation

@mvanhorn

Copy link
Copy Markdown
Contributor

📜 Description

SentryTracer now records the wall-clock time when the deadline timeout is scheduled and, when the timer fires far later than scheduled (more than 2x the configured deadlineTimeout), drops the transaction instead of force-finishing it with now(). The drop follows the existing dropIfNoChildren pattern in finish(): DEBUG log, clear the scope's transaction, cancel timers, no captureTransaction. Timers that fire within the slack behave exactly as before (forceFinish with DEADLINE_EXCEEDED).

💡 Motivation and Context

When an Android app cold-starts and is backgrounded before first frame, the ui.load transaction's 30s deadline timer (a java.util.Timer) is frozen during Doze and fires only hours later when the device wakes. forceFinish then stamps the root span and all children with the current time, producing app-start transactions spanning hours and skewing user-perceived launch metrics. "Timer fired far later than scheduled" is the exact failure signature, so the check stays in platform-neutral core with no Android API and no public API change.

Resolves #5752

💚 How did you test it?

New unit tests in SentryTracerTest: a deadline timeout that fires within the slack still force-finishes with DEADLINE_EXCEEDED; a simulated late fire (scheduled timestamp shifted beyond 2x deadline) drops the transaction, clears it from the scope, and captures nothing. Ran the sentry module test suite.

📝 Checklist

  • I added GH Issue ID & Linear ID
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.
  • Public API changes reviewed by another Mobile SDK team member or implemented according to the develop docs spec.

🔮 Next steps

Comment thread sentry/src/main/java/io/sentry/SentryTracer.java
…ions in tests

Finish the root span when the deadline timer fires too late so the transaction reads as finished (fixes the device-sleep drop test), enable options.isDebug in the two logger-mock tests so DiagnosticLogger forwards to the mock, and apply spotless formatting. Verified locally: spotlessCheck and the full SentryTracerTest suite pass on JDK 17.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 3bc4794. Configure here.

}
}
}
return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Drop path skips finish cleanup

High Severity

The late-deadline drop path finishes the root and clears the scope, but it never runs the cleanup that normal finish() performs before skipping captureTransaction. That leaves the transaction profiler bound, continuous profiling (TRACE lifecycle) unstopped, and compositePerformanceCollector without stop(), so later transactions can fail to profile for the rest of the process after a Doze-delayed deadline drop.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 3bc4794. Configure here.

@mvanhorn

Copy link
Copy Markdown
Contributor Author

Fixed the failing checks in 3bc4794: the root span is now finished when the deadline timer fires too late (so the dropped transaction reads as finished), the two logger-mock tests enable options.isDebug so DiagnosticLogger actually forwards to the mock, and the test file is spotless-formatted. Verified locally on JDK 17: spotlessCheck plus the full SentryTracerTest suite pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect app start transaction duration when app goes in sleep

1 participant