Skip to content

🐛 Align session-ended WebSocket teardown with the latest view's end clocks - #4911

Open
bdibon wants to merge 4 commits into
mainfrom
boris.dibon/fix-websocket-closed-vital
Open

🐛 Align session-ended WebSocket teardown with the latest view's end clocks#4911
bdibon wants to merge 4 commits into
mainfrom
boris.dibon/fix-websocket-closed-vital

Conversation

@bdibon

@bdibon bdibon commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Motivation

When a RUM session expires, open WebSocket connections are finalized with tracking_end_reason: 'session_end'. Until now the teardown used clocksNow() as the end time. Because the active view is ended before the SDK reaches the session-boundary cleanup, clocksNow() lands slightly after the view's end_time — so the resulting websocket-closed vital was dropped during assembly and the resource's end_time fell outside the lifespan of the view it was attached to.

Changes

  • Add ViewHistory.getLatestViewEndClocks(), returning the end clocks of the most recently ended view (reset on SESSION_RENEWED), documented with its intended session-boundary use.
  • On SESSION_EXPIRED, thread those end clocks into flushOpenConnections so the websocket-closed vital startClocks, the resource end_time, and end_view_id all stay within the ending view's window. flushOpenConnections still falls back to clocksNow() when no end clocks are available (e.g. the collection's own stop()).
  • Unit tests for the new getter (set / boundary / reset-on-renew) and the wired session-end path.
  • E2E test asserting the websocket-closed vital and resource end_time do not exceed the associated view's end time.

Ordering note: this relies on trackViews' SESSION_EXPIRED subscriber (registered first) ending the view and notifying AFTER_VIEW_ENDED synchronously before webSocketCollection's subscriber reads getLatestViewEndClocks().

Test instructions

yarn test:unit --spec packages/browser-rum-core/src/domain/contexts/viewHistory.spec.ts
yarn test:unit --spec packages/browser-rum-core/src/domain/resource/webSocketCollection.spec.ts
yarn build:apps && yarn test:e2e -g "websocket-closed vital when the session expires"

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

🤖 Generated with Claude Code

bdibon and others added 4 commits July 24, 2026 15:44
Expose the exact end clocks of the latest ended view so that
session-expiry teardown code can reuse them instead of racing an
independently computed clocksNow().
…locks

Session-expiry teardown flushed open WebSocket connections using
clocksNow(), which could land a few milliseconds after the ended view's
own end clocks. Passing viewHistory.getLatestViewEndClocks() into
flushOpenConnections keeps the session-ended completed event and the
websocket-closed vital aligned with the view boundary.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@cit-pr-commenter-54b7da

Copy link
Copy Markdown

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum 179.09 KiB 179.16 KiB +75 B +0.04%
Rum Profiler 8.43 KiB 8.43 KiB 0 B 0.00%
Rum Recorder 21.12 KiB 21.12 KiB 0 B 0.00%
Logs 55.71 KiB 55.71 KiB 0 B 0.00%
Rum Salesforce N/A 137.14 KiB N/A N/A N/A
Rum Slim 137.06 KiB 137.13 KiB +75 B +0.05%
Worker 22.96 KiB 22.96 KiB 0 B 0.00%

@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Jul 24, 2026

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 77.23% (+0.01%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 700d262 | Docs | Datadog PR Page | Give us feedback!

@bdibon
bdibon marked this pull request as ready for review July 27, 2026 09:54
@bdibon
bdibon requested a review from a team as a code owner July 27, 2026 09:54
@sbarrio
sbarrio requested a review from rgaignault July 28, 2026 07:05
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