Skip to content

feat(core): clear up integrations on dispose#20407

Merged
JPeer264 merged 6 commits intodevelopfrom
jp/cloudflare-oom
Apr 27, 2026
Merged

feat(core): clear up integrations on dispose#20407
JPeer264 merged 6 commits intodevelopfrom
jp/cloudflare-oom

Conversation

@JPeer264
Copy link
Copy Markdown
Member

@JPeer264 JPeer264 commented Apr 20, 2026

closes #19573
closes JS-1829

As with Cloudflare we create a new client on every request, that means that every integration that uses an addHandler and is used by the Cloudflare SDK is makes the client not disposable - so the garbage collector can't remove it properly.

This PR adds a callback for addHandler that basically removes the handler from the global handler array (for now only for integrations, which are used by the Cloudflare SDK). I actually also tried to change the global handler to be a WeakMap, but it still showed some memory leaks with that, so we need to actively remove these callbacks.

For now, to not increase the bundle sizes for core too much, it is actually removing the handlers only in the ServerRuntimeClient, as for browsers it is usually not really an issue.

@linear-code
Copy link
Copy Markdown

linear-code Bot commented Apr 20, 2026

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 20, 2026

size-limit report 📦

Path Size % Change Change
@sentry/browser 26.16 kB +0.12% +30 B 🔺
@sentry/browser - with treeshaking flags 24.63 kB +0.14% +32 B 🔺
@sentry/browser (incl. Tracing) 44.11 kB +0.1% +42 B 🔺
@sentry/browser (incl. Tracing + Span Streaming) 46.11 kB +0.1% +42 B 🔺
@sentry/browser (incl. Tracing, Profiling) 49.06 kB +0.09% +42 B 🔺
@sentry/browser (incl. Tracing, Replay) 83.32 kB +0.07% +57 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 72.81 kB +0.06% +41 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 88 kB +0.07% +53 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 100.65 kB +0.05% +43 B 🔺
@sentry/browser (incl. Feedback) 43.4 kB +0.08% +33 B 🔺
@sentry/browser (incl. sendFeedback) 30.96 kB +0.1% +30 B 🔺
@sentry/browser (incl. FeedbackAsync) 36.14 kB +0.09% +30 B 🔺
@sentry/browser (incl. Metrics) 27.44 kB +0.12% +31 B 🔺
@sentry/browser (incl. Logs) 27.59 kB +0.12% +31 B 🔺
@sentry/browser (incl. Metrics & Logs) 28.28 kB +0.14% +38 B 🔺
@sentry/react 27.9 kB +0.14% +39 B 🔺
@sentry/react (incl. Tracing) 46.35 kB +0.1% +43 B 🔺
@sentry/vue 31.03 kB +0.11% +32 B 🔺
@sentry/vue (incl. Tracing) 45.95 kB +0.08% +36 B 🔺
@sentry/svelte 26.18 kB +0.12% +31 B 🔺
CDN Bundle 28.84 kB +0.14% +38 B 🔺
CDN Bundle (incl. Tracing) 46.65 kB +0.1% +42 B 🔺
CDN Bundle (incl. Logs, Metrics) 30.25 kB +0.2% +59 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) 47.73 kB +0.13% +60 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) 69.22 kB +0.1% +64 B 🔺
CDN Bundle (incl. Tracing, Replay) 83.72 kB +0.06% +44 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 84.79 kB +0.09% +73 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 89.54 kB +0.05% +38 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 90.62 kB +0.06% +54 B 🔺
CDN Bundle - uncompressed 84.55 kB +0.13% +107 B 🔺
CDN Bundle (incl. Tracing) - uncompressed 139.56 kB +0.08% +107 B 🔺
CDN Bundle (incl. Logs, Metrics) - uncompressed 88.75 kB +0.18% +157 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 143.02 kB +0.11% +157 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 212.32 kB +0.08% +157 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 257 kB +0.05% +107 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 260.44 kB +0.07% +157 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 270.7 kB +0.04% +107 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 274.13 kB +0.06% +157 B 🔺
@sentry/nextjs (client) 48.84 kB +0.1% +45 B 🔺
@sentry/sveltekit (client) 44.56 kB +0.09% +39 B 🔺
@sentry/node-core 58.84 kB +0.2% +116 B 🔺
@sentry/node 169.93 kB +0.06% +94 B 🔺
@sentry/node - without tracing 97.65 kB +0.09% +87 B 🔺
@sentry/aws-serverless 114.39 kB +0.08% +84 B 🔺
@sentry/cloudflare (withSentry) - minified 163.56 kB +0.21% +342 B 🔺
@sentry/cloudflare (withSentry) 413.92 kB +0.34% +1.37 kB 🔺

View base workflow run

@JPeer264 JPeer264 self-assigned this Apr 21, 2026
@JPeer264 JPeer264 requested review from mydea and s1gr1d April 21, 2026 07:52
@JPeer264 JPeer264 marked this pull request as ready for review April 21, 2026 08:17
Comment thread packages/core/src/instrument/handlers.ts
Comment thread packages/core/test/lib/server-runtime-client.test.ts
@JPeer264 JPeer264 requested a review from chargome April 21, 2026 09:01
Comment thread packages/core/src/client.ts Outdated
@JPeer264 JPeer264 force-pushed the jp/cloudflare-oom branch from 16defdb to 295ad22 Compare April 22, 2026 08:01
@JPeer264 JPeer264 requested a review from chargome April 22, 2026 08:01
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 3 potential issues.

There are 4 total unresolved issues (including 1 from previous review).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 295ad22. Configure here.

Comment thread .size-limit.js
Comment thread packages/core/src/integrations/conversationId.ts Outdated
Comment thread packages/core/test/lib/instrument/handlers.test.ts
@JPeer264 JPeer264 force-pushed the jp/cloudflare-oom branch 2 times, most recently from 0886f8b to e945863 Compare April 22, 2026 17:17
Comment thread packages/core/src/instrument/console.ts
@JPeer264 JPeer264 force-pushed the jp/cloudflare-oom branch from 14709d4 to d6c0f84 Compare April 27, 2026 08:01
Comment thread packages/core/src/instrument/console.ts
@JPeer264 JPeer264 force-pushed the jp/cloudflare-oom branch from 5697c6b to afdb6f0 Compare April 27, 2026 10:43
Comment thread packages/core/src/instrument/console.ts
@JPeer264 JPeer264 force-pushed the jp/cloudflare-oom branch from 0234943 to 6148dca Compare April 27, 2026 13:43
@JPeer264 JPeer264 enabled auto-merge (squash) April 27, 2026 15:07
@JPeer264 JPeer264 merged commit 786fdf7 into develop Apr 27, 2026
255 checks passed
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.

Investigate in memory leak within console integrations on Cloudflare

4 participants