René's URL Explorer Experiment


Title: Memory leak, instrumentXHR `virtualError` retains every XMLHttpRequest when requests are chained from readystatechange · Issue #24249 · getsentry/sentry-javascript · GitHub

Open Graph Title: Memory leak, instrumentXHR `virtualError` retains every XMLHttpRequest when requests are chained from readystatechange · Issue #24249 · getsentry/sentry-javascript

X Title: Memory leak, instrumentXHR `virtualError` retains every XMLHttpRequest when requests are chained from readystatechange · Issue #24249 · getsentry/sentry-javascript

Description: Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using the latest SDK release https://github.com/...

Open Graph Description: Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using th...

X Description: Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using th...

Opengraph URL: https://github.com/getsentry/sentry-javascript/issues/24249

X: @github

direct link

Domain: github.com

IPv4 address: 140.82.113.3


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Memory leak, instrumentXHR `virtualError` retains every XMLHttpRequest when requests are chained from readystatechange","articleBody":"### Is there an existing issue for this?\n\n- [x] I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues\n- [x] I have reviewed the documentation https://docs.sentry.io/\n- [x] I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases\n\n### How do you use Sentry?\n\nSentry Saas (sentry.io)\n\n### Which SDK are you using?\n\n@sentry/browser\n\n### SDK Version\n\n10.73.0\n\n### Framework Version\n\n_No response_\n\n### Link to Sentry event\n\n_No response_\n\n### Reproduction Example/SDK Setup\n\nMinimal reproduction can be found here https://github.com/augustalfredsson/sentry-xhr-leak-repro\n\nThe reproduction is one HTML page and a Node server. The page loads the Sentry browser bundle from the CDN, calls\n`Sentry.init` with the default integrations, and runs four request chains. Each chain opens the next\n`XMLHttpRequest` from the `readystatechange` callback of the previous one:\n\n```js\nconst next = () => {\n    const xhr = new XMLHttpRequest();\n    xhr.open(\"GET\", \"/api\", true);\n    xhr.onreadystatechange = () => {\n        if (xhr.readyState === 4) {\n            next(); // open the next request on the same call stack\n        }\n    };\n    xhr.send();\n};\nnext();\n```\n\n```js\nSentry.init({\n    dsn: \"https://examplePublicKey@o0.ingest.sentry.io/0\",\n    beforeSend: () => null, // the page never sends events\n});\n```\n\nThis is a common pattern: polling loops, chunked uploads, chained REST calls, and hls.js Low-Latency HLS playlist\nreloads.\n\n### Steps to Reproduce\n\n1. Run `node server.js`, then open `http://localhost:8787/?sentry=on` in Chrome and press Start.\n2. The page shows the size of the JS heap, but you can also see it in DevTools -> Memory panel and take a heap snapshot after 30 seconds. Filter the class list by `XMLHttpRequest`.\n3. Wait one minute and you'll see that the JS heap size keeps growing. Take a second snapshot if you took one earlier. Compare the count and the heap size.\n4. Open `http://localhost:8787/?sentry=off`, press Start, and repeat. This is the control without the Sentry\nbundle. You'll see that the JS heap size doesn't grow.\n\nOr run `node verify.js 40`, which does the same in headless Chromium and counts live `XMLHttpRequest` objects\nthrough CDP `Runtime.queryObjects`.\n\n### Expected Result\n\nA completed `XMLHttpRequest` becomes garbage after its callbacks have run and the JS heap size doesn't grow.\n\n### Actual Result\n\nEvery completed request stays alive for the life of the page. Here's a headless run of 40 seconds with four chains and 8 KB\nresponses:\n\n```\nsentry=on:  completed 224991 requests. Live XMLHttpRequest: 15591 -> 229113. Heap: 28.2 MB -> 400.7 MB\nsentry=off: completed 242321 requests. Live XMLHttpRequest: 4 -> 8.          Heap: 0.7 MB -> 0.7 MB\n```\n\nThe live `XMLHttpRequest` count equals the number of completed requests. Each retained request also pins its\n`responseText` and everything the app's callback closures reference.\n\n### Additional Context\n\n**What we think happens** \nIn `packages/browser-utils/src/instrument/xhr.ts`, the `open` wrapper\ncreates `const virtualError = new Error()` for every request and never releases it. The\n`setRequestHeader` Proxy that the wrapper puts on the XHR instance lives in the same\nfunction scope, so it keeps `virtualError` alive for as long as the XHR is alive. Nobody\nreads `virtualError.stack`, so V8 keeps the raw stack frames, and each raw frame holds its\nreceiver object. When request N+1 is opened inside the callback of request N, one of those\nframes has request N as its receiver. So request N+1 retains request N, which retains\nrequest N-1, and so on. The request in flight is a Blink pending activity and thus a GC\nroot, and the whole chain hangs from it.\n\nThe path from a heap snapshot:\n\n```\nBlink \"Pending activities\" (the one in-flight XHR)\n-> XMLHttpRequest#N\n-> own property `setRequestHeader` (Proxy)\n-> Proxy `apply` closure -> closure context of the `open` handler\n-> `virtualError` -> raw stack frames\n-> frame receiver = XMLHttpRequest#N-1\n-> ... -> XMLHttpRequest#N-2 -> ...\n```\n\n**Related PR** \n#22216 (10.66.0) removes the `readystatechange` listener after the request\ncompletes. That does not break this chain, because the `setRequestHeader` Proxy still holds\nthe context.\n\n**Possible fixes** \nAny one of these breaks the chain:\n\n- Set `virtualError = undefined` after the `readyState === 4` handler ran.\n- Create the `setRequestHeader` Proxy in its own function, so it does not share a closure\ncontext with `virtualError`.\n- Keep only the formatted `stack` string, or hold `virtualError` in a `WeakRef`.\n\n**Workaround**\nTurn off the XHR instrumentation. Both default integrations call\n`instrumentXHR`, so both options are needed. This loses XHR breadcrumbs.\n\n```js\nintegrations: [\n    Sentry.breadcrumbsIntegration({ xhr: false }),\n    Sentry.browserApiErrorsIntegration({ XMLHttpRequest: false }),\n],\n```\n\n**Environment** \nChrome 151.0.7922.176, macOS 26.6.2. Headless numbers from Chromium 1200\n(Playwright 1.57) on macOS.\n\n### Priority\n\n_No response_","author":{"url":"https://github.com/augustalfredsson","@type":"Person","name":"augustalfredsson"},"datePublished":"2026-09-09T13:17:39Z","url":"https://github.com/getsentry/sentry-javascript/issues/24249"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:4fa49363-e22e-61d9-e9e1-27e6afd92372
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id8082:3B1B50:7AC4A5:A2B4BF:6B04CC56
html-safe-nonce74ff07c4e9b5741d23e6db4bdbebb317fa2d0037fd2663ef9989ee86acfcdf94
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MDgyOjNCMUI1MDo3QUM0QTU6QTJCNEJGOjZCMDRDQzU2IiwidmlzaXRvcl9pZCI6IjM3NTYyNDc3ODAzMzE2NzA2MTQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac250461c8cd233a28d6f5f48550a183c940b6f8b7d912ca1276dbcfeb06f41663
hovercard-subject-tagissue:5399945495
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/getsentry/sentry-javascript/24249/issue_layout
twitter:imagehttps://opengraph.githubassets.com/896f766adb977476e02f3619bf19e9512874bd565a5bb584d6699d9c38e081ac/getsentry/sentry-javascript/issues/24249
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/896f766adb977476e02f3619bf19e9512874bd565a5bb584d6699d9c38e081ac/getsentry/sentry-javascript/issues/24249
og:image:altIs there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using th...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameaugustalfredsson
hostnamegithub.com
expected-hostnamegithub.com
None27ed421e5c2dac040a37529b5b9191edcc4a3de70521471e81fb4b4d9dc2aa7d
turbo-cache-controlno-preview
go-importgithub.com/getsentry/sentry-javascript git https://github.com/getsentry/sentry-javascript.git
octolytics-dimension-user_id1396951
octolytics-dimension-user_logingetsentry
octolytics-dimension-repository_id3328572
octolytics-dimension-repository_nwogetsentry/sentry-javascript
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id3328572
octolytics-dimension-repository_network_root_nwogetsentry/sentry-javascript
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release63dc19014c621c67306d7899c04c78dcd0d95803
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/getsentry/sentry-javascript/issues/24249#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgetsentry%2Fsentry-javascript%2Fissues%2F24249
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgetsentry%2Fsentry-javascript%2Fissues%2F24249
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=getsentry%2Fsentry-javascript
Reloadhttps://github.com/getsentry/sentry-javascript/issues/24249
Reloadhttps://github.com/getsentry/sentry-javascript/issues/24249
Reloadhttps://github.com/getsentry/sentry-javascript/issues/24249
getsentryhttps://github.com/getsentry
sentry-javascripthttps://github.com/getsentry/sentry-javascript
Codehttps://github.com/getsentry/sentry-javascript
Issues333 (333)https://github.com/getsentry/sentry-javascript/issues
Pull requests51 (51)https://github.com/getsentry/sentry-javascript/pulls
Discussionshttps://github.com/getsentry/sentry-javascript/discussions
Actionshttps://github.com/getsentry/sentry-javascript/actions
Security and quality7 (7)https://github.com/getsentry/sentry-javascript/security
Insightshttps://github.com/getsentry/sentry-javascript/insights
https://github.com/getsentry/sentry-javascript
New issuehttps://github.com/login?return_to=https://github.com/getsentry/sentry-javascript/issues/24249
New issuehttps://github.com/login?return_to=https://github.com/getsentry/sentry-javascript/issues/24249
#24277https://github.com/getsentry/sentry-javascript/pull/24277
Memory leak, instrumentXHR virtualError retains every XMLHttpRequest when requests are chained from readystatechangehttps://github.com/getsentry/sentry-javascript/issues/24249#top
#24277https://github.com/getsentry/sentry-javascript/pull/24277
https://github.com/logaretm
Browserhttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Browser%22
Bughttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Bug%22
https://github.com/augustalfredsson
augustalfredssonhttps://github.com/augustalfredsson
on Sep 9, 2026https://github.com/getsentry/sentry-javascript/issues/24249#issue-5399945495
https://github.com/getsentry/sentry-javascript/issueshttps://github.com/getsentry/sentry-javascript/issues
https://docs.sentry.io/https://docs.sentry.io/
https://github.com/getsentry/sentry-javascript/releaseshttps://github.com/getsentry/sentry-javascript/releases
https://github.com/augustalfredsson/sentry-xhr-leak-reprohttps://github.com/augustalfredsson/sentry-xhr-leak-repro
#22216https://github.com/getsentry/sentry-javascript/pull/22216
augustalfredssonhttps://github.com/augustalfredsson
Bughttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Bug%22
on Sep 9, 2026https://github.com/getsentry/sentry-javascript/issues/24249#event-30831094015
getsantryhttps://github.com/apps/getsantry
Waiting for: Product Ownerhttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Waiting%20for%3A%20Product%20Owner%22
on Sep 9, 2026https://github.com/getsentry/sentry-javascript/issues/24249#event-30831095654
getsantryhttps://github.com/apps/getsantry
GitHub Issues with 👀 3https://github.com/orgs/getsentry/projects/227
on Sep 9, 2026https://github.com/getsentry/sentry-javascript/issues/24249#event-30831160492
https://github.com/apps/linear-code
linear-codehttps://github.com/apps/linear-code
on Sep 9, 2026https://github.com/getsentry/sentry-javascript/issues/24249#issuecomment-5602495476
Linear Codehttps://linear.app
JS-3640https://linear.app/getsentry/issue/JS-3640
getsantryhttps://github.com/apps/getsantry
GitHub Issues with 👀 3https://github.com/orgs/getsentry/projects/227
on Sep 9, 2026https://github.com/getsentry/sentry-javascript/issues/24249
github-actionshttps://github.com/apps/github-actions
Browserhttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Browser%22
on Sep 9, 2026https://github.com/getsentry/sentry-javascript/issues/24249#event-30831104085
logaretmhttps://github.com/logaretm
on Sep 10, 2026https://github.com/getsentry/sentry-javascript/issues/24249#event-30877894238
https://github.com/logaretm
logaretmhttps://github.com/logaretm
on Sep 10, 2026https://github.com/getsentry/sentry-javascript/issues/24249#issuecomment-5613573621
Linear Codehttps://linear.app
getsantryhttps://github.com/apps/getsantry
Waiting for: Product Ownerhttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Waiting%20for%3A%20Product%20Owner%22
on Sep 10, 2026https://github.com/getsentry/sentry-javascript/issues/24249#event-30877905706
getsantryhttps://github.com/apps/getsantry
GitHub Issues with 👀 3https://github.com/orgs/getsentry/projects/227
on Sep 10, 2026https://github.com/getsentry/sentry-javascript/issues/24249
logaretmhttps://github.com/logaretm
completedhttps://github.com/getsentry/sentry-javascript/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#24277https://github.com/getsentry/sentry-javascript/pull/24277
on Sep 10, 2026https://github.com/getsentry/sentry-javascript/issues/24249#event-30907636206
nabi-noorhttps://github.com/nabi-noor
on Sep 10, 2026https://github.com/getsentry/sentry-javascript/issues/24249#event-30908087207
fix(browser): Release the XHR `virtualError` once the request complet…https://github.com/nabi-noor/sentry-javascript/commit/56fc0885b480d27244960fd078de1daebdcc5412
https://docs.github.com/articles/closing-issues-via-commit-messages
56fc088https://github.com/nabi-noor/sentry-javascript/commit/56fc0885b480d27244960fd078de1daebdcc5412
Sign up for freehttps://github.com/signup?return_to=https://github.com/getsentry/sentry-javascript/issues/24249
Sign in to commenthttps://github.com/login?return_to=https://github.com/getsentry/sentry-javascript/issues/24249
logaretmhttps://github.com/logaretm
Browserhttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Browser%22
Bughttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Bug%22
GitHub Issues with 👀 3https://github.com/orgs/getsentry/projects/227
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Response headers:
Servergithub.com
Content-Typetext/html; charset=utf-8
Cache-Controlmax-age=0, private, must-revalidate

Viewport: width=device-width


URLs of crawlers that visited me.