Skip to content

🐛 [RUM Profiler] Fix stateReason not updated on stop and cleanup tasks accumulation#4171

Open
thomasbertet wants to merge 2 commits intomainfrom
thomas.bertet/PROF-13743-fix-profiler-stop-state-and-cleanup
Open

🐛 [RUM Profiler] Fix stateReason not updated on stop and cleanup tasks accumulation#4171
thomasbertet wants to merge 2 commits intomainfrom
thomas.bertet/PROF-13743-fix-profiler-stop-state-and-cleanup

Conversation

@thomasbertet
Copy link
Collaborator

Motivation

Two issues found in the profiler state machine after the recent sync state fix (#4152):

  1. stopProfilerInstance does not update stateReason when the profiler is already in stopped state. If SESSION_EXPIRED fires first (setting stateReason to session-expired), then the user calls stop(), the reason stays session-expired. On the next SESSION_RENEWED, the profiler restarts against the user's intent.

  2. globalCleanupTasks array is never cleared after forEach cleanup in stopProfiling. Stale function references accumulate across start/stop cycles.

Changes

  • stopProfilerInstance: when already stopped, update stateReason if the new reason is stopped-by-user, so that SESSION_RENEWED respects the user's explicit stop.
  • stopProfiling: reset globalCleanupTasks.length = 0 after invoking all cleanup functions.

Test instructions

  • Run yarn test:unit --spec packages/rum/src/domain/profiling/profiler.spec.ts
  • New test: "should not restart profiling on session renewal if user called stop after session expiration"

Checklist

  • Tested locally
  • Tested on staging
  • Added unit tests for this change.
  • Added e2e/integration tests for this change.
  • Updated documentation and/or relevant AGENTS.md file

stopProfilerInstance did not update stateReason when the profiler was
already in stopped state. This meant calling stop() after SESSION_EXPIRED
left stateReason as 'session-expired', causing SESSION_RENEWED to restart
the profiler against the user's intent.
The array was never reset after forEach, causing stale cleanup function
references to accumulate across start/stop cycles.
@thomasbertet thomasbertet marked this pull request as ready for review February 12, 2026 17:56
@thomasbertet thomasbertet requested a review from a team as a code owner February 12, 2026 17:56
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.

1 participant