Skip to content

fix(browser): Release the XHR virtualError once the request completed - #24277

Merged
logaretm merged 2 commits into
developfrom
awad/fix-xhr-virtual-error-retention
Sep 10, 2026
Merged

fix(browser): Release the XHR virtualError once the request completed#24277
logaretm merged 2 commits into
developfrom
awad/fix-xhr-virtual-error-retention

Conversation

@logaretm

@logaretm logaretm commented Sep 10, 2026

Copy link
Copy Markdown
Member

Releases the virtualError that instrumentXHR captures once the request has completed, so chained XHRs stop retaining each other.

open() captures a new Error() per request for the HttpClient integration. Nobody reads .stack, so V8 keeps the raw frames, and a raw frame keeps its receiver alive. In other words, every completed request holds a stack frame pointing at the one before it, so they pile up like a linked list.

The alternative was to hoist setRequestHeader proxy in a module-level function so its handler holds the virtualError, but that only unhooks the error for pages that register addEventListener. Pages that set onreadystatechange will need a different fix, so clearing the error manually fixes it for both.

Fixes #24249

`instrumentXHR` captures a `new Error()` per `open()` call so the HttpClient integration can
report where a failed request came from. Nothing ever formats that stack in the common case, so
V8 keeps the raw frames, and a raw frame keeps its receiver alive. When a request is opened from
the `readystatechange` callback of the previous one, the receiver of one of those frames is the
previous XMLHttpRequest, so every completed request in the chain stays reachable from the one
currently in flight.

The error is only needed while the completion handlers run, so drop it right after.

Fixes #24249
@github-actions

github-actions Bot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 28.82 kB +0.06% +16 B 🔺
@sentry/browser - with treeshaking flags 27.13 kB +0.08% +20 B 🔺
@sentry/browser - with treeshaking flags tracing without tracing 27.02 kB +0.06% +16 B 🔺
@sentry/browser (incl. Tracing) 50.19 kB +1.99% +975 B 🔺
@sentry/browser (incl. Tracing + Span Streaming) 50.21 kB +2.01% +987 B 🔺
@sentry/browser (incl. Tracing, Profiling) 53.19 kB +2.04% +1.06 kB 🔺
@sentry/browser (incl. Tracing, Replay) 89.68 kB +1.04% +922 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 78.8 kB +1.09% +845 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 94.38 kB +1.01% +938 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 107.39 kB +0.96% +1.01 kB 🔺
@sentry/browser (incl. Feedback) 46.31 kB +0.03% +11 B 🔺
@sentry/browser (incl. sendFeedback) 33.87 kB +0.04% +11 B 🔺
@sentry/browser (incl. FeedbackAsync) 38.99 kB +0.05% +19 B 🔺
@sentry/browser (incl. Metrics) 29.85 kB +0.1% +29 B 🔺
@sentry/browser (incl. Logs) 30.11 kB +0.08% +24 B 🔺
@sentry/browser (incl. Metrics & Logs) 30.79 kB +0.13% +39 B 🔺
@sentry/react 30.57 kB +0.08% +22 B 🔺
@sentry/react (incl. Tracing) 52.52 kB +1.87% +959 B 🔺
@sentry/vue 36.07 kB +0.07% +23 B 🔺
@sentry/vue (incl. Tracing) 52.43 kB +1.87% +959 B 🔺
@sentry/svelte 28.85 kB +0.07% +20 B 🔺
CDN Bundle 30.58 kB +0.09% +27 B 🔺
CDN Bundle (incl. Tracing) 50.67 kB +1.89% +939 B 🔺
CDN Bundle (incl. Logs, Metrics) 32.84 kB +0.07% +22 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) 52.63 kB +1.81% +934 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) 73.53 kB +0.08% +55 B 🔺
CDN Bundle (incl. Tracing, Replay) 88.21 kB +1.06% +922 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 90.17 kB +1.12% +993 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 94.23 kB +1.09% +1.02 kB 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 96.26 kB +1.11% +1.05 kB 🔺
CDN Bundle - uncompressed 90.48 kB +0.03% +21 B 🔺
CDN Bundle (incl. Tracing) - uncompressed 151.36 kB +2.16% +3.19 kB 🔺
CDN Bundle (incl. Logs, Metrics) - uncompressed 97.05 kB +0.03% +21 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 157.33 kB +2.08% +3.19 kB 🔺
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 226.46 kB +0.08% +172 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 270.93 kB +1.19% +3.17 kB 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 276.88 kB +1.16% +3.17 kB 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 284.64 kB +1.13% +3.17 kB 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 290.58 kB +1.11% +3.17 kB 🔺
@sentry/nextjs (client) 54.85 kB +1.58% +849 B 🔺
@sentry/sveltekit (client) 50.63 kB +1.97% +976 B 🔺
@sentry/core/server 36.99 kB - -
@sentry/core/browser 13.55 kB - -
@sentry/node 127.95 kB +0.13% +157 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 81.61 kB - -
@sentry/node - without tracing 88.73 kB +0.03% +20 B 🔺
@sentry/node - without channel injection 107.17 kB +0.13% +137 B 🔺
@sentry/aws-serverless 97.12 kB +0.03% +25 B 🔺
@sentry/cloudflare (withSentry) - minified 202.05 kB +0.04% +74 B 🔺
@sentry/cloudflare (withSentry) 502.91 kB +0.05% +232 B 🔺

View base workflow run

@logaretm

Copy link
Copy Markdown
Member Author

bugbot run

@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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 1633639. Configure here.

@logaretm
logaretm marked this pull request as ready for review September 10, 2026 05:33
@logaretm
logaretm requested a review from a team as a code owner September 10, 2026 05:33
@logaretm
logaretm requested review from Lms24 and msonnb and removed request for a team September 10, 2026 05:33
@logaretm
logaretm merged commit 56fc088 into develop Sep 10, 2026
231 of 232 checks passed
@logaretm
logaretm deleted the awad/fix-xhr-virtual-error-retention branch September 10, 2026 14:06
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.

Memory leak, instrumentXHR virtualError retains every XMLHttpRequest when requests are chained from readystatechange

2 participants