René's URL Explorer Experiment


Title: Memory leak: contextWrapper on ServerResponse.close retains async context across keep-alive connections (Fastify) · Issue #20174 · getsentry/sentry-javascript · GitHub

Open Graph Title: Memory leak: contextWrapper on ServerResponse.close retains async context across keep-alive connections (Fastify) · Issue #20174 · getsentry/sentry-javascript

X Title: Memory leak: contextWrapper on ServerResponse.close retains async context across keep-alive connections (Fastify) · Issue #20174 · 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/20174

X: @github

direct link

Domain: github.com

IPv4 address: 140.82.112.4


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Memory leak: contextWrapper on ServerResponse.close retains async context across keep-alive connections (Fastify)","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/node - fastify\n\n### SDK Version\n\n10.47.0\n\n### Framework Version\n\nFastify 5.8.4, Node.js 22.15.1\n\n### Link to Sentry event\n\n_No response_\n\n### Reproduction Example/SDK Setup\n\n\n  ```ts\n  import * as Sentry from \"@sentry/node\";\n  import { nodeProfilingIntegration } from \"@sentry/profiling-node\";\n\n  Sentry.init({\n    dsn: \"...\",\n    tracesSampleRate: 0.1,\n    integrations: [nodeProfilingIntegration()],\n    profilesSampleRate: 1.0,\n  });\n\n  Fastify setup:\n\n  Sentry.setupFastifyErrorHandler(app);\n```\n\n### Steps to Reproduce\n\n 1. Set up a Fastify v5 app with setupFastifyErrorHandler and a database (pg/Kysely)\n  2. Add route handlers that query and return ~6000 rows\n  3. Run a load test with concurrent HTTP clients using keep-alive connections\n  4. Take 3 heap snapshots over 10 minutes and run memlab find-leaks\n\n### Expected Result\n\nMemory from completed request handlers should be freed after the response is sent.\n\n### Actual Result\n\nMemory grows ~11 MB/hour in production (ECS, 1820 MB). OOM kill after ~24h.\n\nmemlab find-leaks shows 23.6 MB retained by a single request's query results that are never freed. The retention chain:\n\n  TCPSocketWrap (alive — HTTP keep-alive)\n    → Socket → _httpMessage → ServerResponse [23.6MB]\n      → _events.close → [contextWrapper]        ← added by Sentry\n        → context → callback chain\n          → fulfilled → Promise → PromiseReaction\n            → Generator (suspended async function) [23.6MB]\n              → parameters_and_registers          ← local variables (query results)\n\n  Sentry's contextWrapper is registered as a listener on ServerResponse._events.close. This event only fires when the underlying socket closes, not when the response finishes. With HTTP/1.1 keep-alive, the socket persists across requests, so every traced request's full async context, including database query results held in async function local variables (V8 Generator parameters_and_registers), is retained until the socket closes.\n\n  With nodeProfilingIntegration(), PROFILE_MAP (LRUMap) adds a second retention path that keeps scopes alive even after socket close.\n\n\n\n### Additional Context\n\nProposal: Clean up the contextWrapper listener when the response finishes (finish event or Fastify onResponse hook) rather than relying on socket close.\n\n### Priority\n\n\u003csub>React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding `+1` or `me too`, to help us triage it.\u003c/sub>","author":{"url":"https://github.com/jerosa","@type":"Person","name":"jerosa"},"datePublished":"2026-04-09T14:56:48Z","url":"https://github.com/getsentry/sentry-javascript/issues/20174"}

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:9f0742d7-9326-360e-6a34-a6bddde3764b
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idCA7A:49A58:724045:9AD6E0:6B044529
html-safe-noncee7b1dfa41b0afbf1f70912f1846215a57762eb0fa33dab29db1b4a1057d91a52
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQTdBOjQ5QTU4OjcyNDA0NTo5QUQ2RTA6NkIwNDQ1MjkiLCJ2aXNpdG9yX2lkIjoiNDk1MDcyNTU3NjAxODM4MDA3MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmaca8ba38acc5d897c0f9bcee190f039955bab2f7b2accc5ef12279d8117b7a5719
hovercard-subject-tagissue:4233121586
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/20174/issue_layout
twitter:imagehttps://opengraph.githubassets.com/cc76ca6f337557ed2b9a7e37c814dd8d7b826528ab1b4ebb4695d2793209ce91/getsentry/sentry-javascript/issues/20174
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/cc76ca6f337557ed2b9a7e37c814dd8d7b826528ab1b4ebb4695d2793209ce91/getsentry/sentry-javascript/issues/20174
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:usernamejerosa
hostnamegithub.com
expected-hostnamegithub.com
Noned4495c3631faba668036f176d1f5946901c5172efd73a6edb984029e7d4f8e46
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
release9ac4337fb7c6a5846cdfdb1a04f154d3c33ebc77
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/getsentry/sentry-javascript/issues/20174#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgetsentry%2Fsentry-javascript%2Fissues%2F20174
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%2F20174
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/20174
Reloadhttps://github.com/getsentry/sentry-javascript/issues/20174
Reloadhttps://github.com/getsentry/sentry-javascript/issues/20174
getsentryhttps://github.com/getsentry
sentry-javascripthttps://github.com/getsentry/sentry-javascript
Codehttps://github.com/getsentry/sentry-javascript
Issues339 (339)https://github.com/getsentry/sentry-javascript/issues
Pull requests53 (53)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/20174
New issuehttps://github.com/login?return_to=https://github.com/getsentry/sentry-javascript/issues/20174
#20328https://github.com/getsentry/sentry-javascript/pull/20328
Memory leak: contextWrapper on ServerResponse.close retains async context across keep-alive connections (Fastify)https://github.com/getsentry/sentry-javascript/issues/20174#top
#20328https://github.com/getsentry/sentry-javascript/pull/20328
https://github.com/JPeer264
Bughttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Bug%22
Fastifyhttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Fastify%22
Node.jshttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Node.js%22
https://github.com/jerosa
jerosahttps://github.com/jerosa
on Apr 9, 2026https://github.com/getsentry/sentry-javascript/issues/20174#issue-4233121586
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
jerosahttps://github.com/jerosa
Bughttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Bug%22
on Apr 9, 2026https://github.com/getsentry/sentry-javascript/issues/20174#event-24340625809
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 Apr 9, 2026https://github.com/getsentry/sentry-javascript/issues/20174#event-24340627676
getsantryhttps://github.com/apps/getsantry
GitHub Issues with 👀 3https://github.com/orgs/getsentry/projects/227
on Apr 9, 2026https://github.com/getsentry/sentry-javascript/issues/20174#event-24340631832
getsantryhttps://github.com/apps/getsantry
GitHub Issues with 👀 3https://github.com/orgs/getsentry/projects/227
on Apr 9, 2026https://github.com/getsentry/sentry-javascript/issues/20174
https://github.com/apps/linear-code
linear-codehttps://github.com/apps/linear-code
on Apr 9, 2026https://github.com/getsentry/sentry-javascript/issues/20174#issuecomment-4215220478
Linear Codehttps://linear.app
JS-2106https://linear.app/getsentry/issue/JS-2106/memory-leak-contextwrapper-on-serverresponseclose-retains-async
github-actionshttps://github.com/apps/github-actions
Fastifyhttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Fastify%22
on Apr 9, 2026https://github.com/getsentry/sentry-javascript/issues/20174#event-24340635194
linear-codehttps://github.com/apps/linear-code
Node.jshttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Node.js%22
on Apr 9, 2026https://github.com/getsentry/sentry-javascript/issues/20174#event-24340668495
https://github.com/s1gr1d
s1gr1dhttps://github.com/s1gr1d
on Apr 10, 2026https://github.com/getsentry/sentry-javascript/issues/20174#issuecomment-4224388040
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 Apr 10, 2026https://github.com/getsentry/sentry-javascript/issues/20174#event-24383470836
getsantryhttps://github.com/apps/getsantry
GitHub Issues with 👀 3https://github.com/orgs/getsentry/projects/227
on Apr 10, 2026https://github.com/getsentry/sentry-javascript/issues/20174
s1gr1dhttps://github.com/s1gr1d
on Apr 10, 2026https://github.com/getsentry/sentry-javascript/issues/20174#event-24383476221
https://github.com/s1gr1d
s1gr1dhttps://github.com/s1gr1d
on Apr 13, 2026https://github.com/getsentry/sentry-javascript/issues/20174#issuecomment-4236296841
https://github.com/s1gr1d/sentry-js-20174-fastify-memoryhttps://github.com/s1gr1d/sentry-js-20174-fastify-memory
s1gr1dhttps://github.com/s1gr1d
Waiting for: Communityhttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Waiting%20for%3A%20Community%22
on Apr 13, 2026https://github.com/getsentry/sentry-javascript/issues/20174#event-24445282300
getsantryhttps://github.com/apps/getsantry
GitHub Issues with 👀 3https://github.com/orgs/getsentry/projects/227
on Apr 13, 2026https://github.com/getsentry/sentry-javascript/issues/20174
s1gr1dhttps://github.com/s1gr1d
on Apr 13, 2026https://github.com/getsentry/sentry-javascript/issues/20174#event-24446180512
jerosahttps://github.com/jerosa
on Apr 13, 2026https://github.com/getsentry/sentry-javascript/issues/20174#event-24453218211
Surface the leak: profiling + real pg + layered asynchttps://github.com/jerosa/sentry-js-20174-fastify-memory/commit/3667c943bc1c677a2745d0693fa740173766ab88
3667c94https://github.com/jerosa/sentry-js-20174-fastify-memory/commit/3667c943bc1c677a2745d0693fa740173766ab88
https://github.com/jerosa
jerosahttps://github.com/jerosa
on Apr 13, 2026https://github.com/getsentry/sentry-javascript/issues/20174#issuecomment-4237807673
@s1gr1dhttps://github.com/s1gr1d
s1gr1d/sentry-js-20174-fastify-memory#1https://github.com/s1gr1d/sentry-js-20174-fastify-memory/pull/1
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
Waiting for: Communityhttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Waiting%20for%3A%20Community%22
on Apr 13, 2026https://github.com/getsentry/sentry-javascript/issues/20174#event-24453283733
getsantryhttps://github.com/apps/getsantry
GitHub Issues with 👀 3https://github.com/orgs/getsentry/projects/227
on Apr 13, 2026https://github.com/getsentry/sentry-javascript/issues/20174
s1gr1dhttps://github.com/s1gr1d
Waiting for: Product Ownerhttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Waiting%20for%3A%20Product%20Owner%22
on Apr 14, 2026https://github.com/getsentry/sentry-javascript/issues/20174#event-24491685360
getsantryhttps://github.com/apps/getsantry
GitHub Issues with 👀 3https://github.com/orgs/getsentry/projects/227
on Apr 14, 2026https://github.com/getsentry/sentry-javascript/issues/20174
JPeer264https://github.com/JPeer264
on Apr 15, 2026https://github.com/getsentry/sentry-javascript/issues/20174#event-24522762615
fix(opentelemetry): Use WeakRef for context stored on scope to preven…https://github.com/getsentry/sentry-javascript/commit/ffc2c6846e140c7e114b011b7a7ea71e01cdca19
https://docs.github.com/articles/closing-issues-via-commit-messages
ffc2c68https://github.com/getsentry/sentry-javascript/commit/ffc2c6846e140c7e114b011b7a7ea71e01cdca19
fix(opentelemetry): Use WeakRef for context stored on scope to preven…https://github.com/getsentry/sentry-javascript/commit/46fdf73e65f3821f350040a21b19c4c2d1e4c5ef
https://docs.github.com/articles/closing-issues-via-commit-messages
46fdf73https://github.com/getsentry/sentry-javascript/commit/46fdf73e65f3821f350040a21b19c4c2d1e4c5ef
linear-codehttps://github.com/apps/linear-code
JPeer264https://github.com/JPeer264
on Apr 15, 2026https://github.com/getsentry/sentry-javascript/issues/20174#event-24526034294
JPeer264https://github.com/JPeer264
on Apr 15, 2026https://github.com/getsentry/sentry-javascript/issues/20174#event-24529461323
fix(opentelemetry): Use WeakRef for context stored on scope to preven…https://github.com/getsentry/sentry-javascript/commit/40ab2fff29143c29b1a56fda17846a29c0e58957
https://docs.github.com/articles/closing-issues-via-commit-messages
40ab2ffhttps://github.com/getsentry/sentry-javascript/commit/40ab2fff29143c29b1a56fda17846a29c0e58957
JPeer264https://github.com/JPeer264
completedhttps://github.com/getsentry/sentry-javascript/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#20328https://github.com/getsentry/sentry-javascript/pull/20328
on Apr 15, 2026https://github.com/getsentry/sentry-javascript/issues/20174#event-24539947429
https://github.com/apps/github-actions
github-actionshttps://github.com/apps/github-actions
on Apr 16, 2026https://github.com/getsentry/sentry-javascript/issues/20174#issuecomment-4261108640
GitHub Actionshttps://help.github.com/en/actions
#20328https://github.com/getsentry/sentry-javascript/pull/20328
10.49.0 releasehttps://github.com/getsentry/sentry-javascript/releases/tag/10.49.0
Sign up for freehttps://github.com/signup?return_to=https://github.com/getsentry/sentry-javascript/issues/20174
Sign in to commenthttps://github.com/login?return_to=https://github.com/getsentry/sentry-javascript/issues/20174
JPeer264https://github.com/JPeer264
Bughttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Bug%22
Fastifyhttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Fastify%22
Node.jshttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Node.js%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.