Skip to content

Finished idle spans retain their final timeout callback #26936

Done

Description

@efstathiosntonas

What happens

startIdleSpan schedules a final timeout so an unfinished span has a hard deadline. When a span ends before that deadline, onIdleSpanEnded sets _finished and runs its cleanup hooks. The final timeout handle is discarded when the timer is scheduled, so the cleanup cannot cancel it.

The pending callback keeps the finished span and its captured state reachable until the timer fires. By then, _finished makes the callback a no-op. With frequent navigation, several generations of finished spans can stay in memory at once. The React Native navigation integration’s ten-minute deadline makes that retention window especially visible. Sentry core source

Hypothetical scenario

  1. Imagine a user switching repeatedly between screens in an app with navigation tracing enabled.
  2. Each navigation span finishes through its normal idle path.
  3. If you inspected the timer queue after the app settled, each finished span’s final callback would still be scheduled until its original deadline.

Proposed fix

Save the final timeout handle and clear it in onIdleSpanEnded. An unfinished span keeps its existing deadline and still ends with deadline_exceeded if the timer fires.

   let _idleTimeoutID: ReturnType<typeof setTimeout> | undefined;
   let _childSpanTimeoutID: ReturnType<typeof setTimeout> | undefined;
+  let _finalTimeoutID: ReturnType<typeof setTimeout> | undefined;

   function onIdleSpanEnded(endTimestamp: number): void {
     _finished = true;
+    clearTimeout(_finalTimeoutID);
+    _finalTimeoutID = undefined;
     activities.clear();

-  setTimeout(() => {
+  _finalTimeoutID = setTimeout(() => {
     if (!_finished) {

Activity

  1. linear-code commented on Nov 26, 2026

    @linear-code
  2. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Nov 26, 2026
  3. added
    javascript
    on Nov 26, 2026
  4. self-assigned this
    on Nov 26, 2026
  5. logaretm commented on Nov 26, 2026

    @logaretm
    Member

    Thanks for the report, I created a PR for it but it may introduce a behavior change that we need to consider first.

  6. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Nov 26, 2026
  7. efstathiosntonas commented on Nov 27, 2026

    @efstathiosntonas
    Author

    Thanks @logaretm, I was experiencing memory growth on my react-native app and this one was really hard to track down. Even claude with argent profiling missed it 👀

    edit: I understand that timers are being cleared at some point but, in our social app where the users are jumping screens really fast this grows fast.

  8. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Nov 27, 2026
  9. github-actions commented on Nov 27, 2026

    @github-actions
    Contributor

    A PR closing this issue has just been released 🚀

    This issue was referenced by PR #26938, which was included in the 11.20.0 release.

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

Metadata

Metadata

Assignees

Labels

BugSpansjavascript

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions