Skip to content

Finished idle spans retain their final timeout callback #26936

Backlog

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSpansWaiting for: Product Ownerjavascript

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions