Skip to content

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

Open
JPeer264 wants to merge 6 commits intodevelopfrom
jp/cloudflare-oom
Open

feat(core): clear up integrations on dispose#20407
JPeer264 wants to merge 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 📦

⚠️ Warning: Base artifact is not the latest one, because the latest workflow run is not done yet. This may lead to incorrect results. Try to re-run all tests to get up to date results.

Path Size % Change Change
⛔️ @sentry/browser (max: 26 kB) 26.01 kB +0.11% +28 B 🔺
@sentry/browser - with treeshaking flags 24.5 kB +0.14% +33 B 🔺
@sentry/browser (incl. Tracing) 43.95 kB +0.1% +40 B 🔺
@sentry/browser (incl. Tracing + Span Streaming) 45.58 kB +0.09% +39 B 🔺
@sentry/browser (incl. Tracing, Profiling) 48.91 kB +0.09% +40 B 🔺
@sentry/browser (incl. Tracing, Replay) 83.16 kB +0.06% +45 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 72.64 kB +0.06% +42 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 87.83 kB +0.05% +42 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 100.09 kB +0.05% +41 B 🔺
@sentry/browser (incl. Feedback) 42.81 kB +0.08% +30 B 🔺
@sentry/browser (incl. sendFeedback) 30.68 kB +0.1% +30 B 🔺
@sentry/browser (incl. FeedbackAsync) 35.67 kB +0.1% +33 B 🔺
@sentry/browser (incl. Metrics) 27.3 kB +0.12% +31 B 🔺
@sentry/browser (incl. Logs) 27.43 kB +0.12% +31 B 🔺
@sentry/browser (incl. Metrics & Logs) 28.13 kB +0.13% +34 B 🔺
@sentry/react 27.77 kB +0.14% +37 B 🔺
@sentry/react (incl. Tracing) 46.18 kB +0.09% +38 B 🔺
@sentry/vue 30.86 kB +0.11% +33 B 🔺
@sentry/vue (incl. Tracing) 45.76 kB +0.09% +37 B 🔺
⛔️ @sentry/svelte (max: 26 kB) 26.03 kB +0.12% +30 B 🔺
CDN Bundle 28.69 kB +0.14% +38 B 🔺
CDN Bundle (incl. Tracing) 46.17 kB +0.1% +43 B 🔺
CDN Bundle (incl. Logs, Metrics) 30.1 kB +0.2% +59 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) 47.24 kB +0.14% +65 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) 69.09 kB +0.1% +66 B 🔺
CDN Bundle (incl. Tracing, Replay) 83.24 kB +0.06% +44 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 84.29 kB +0.08% +66 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 88.72 kB +0.05% +39 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 89.82 kB +0.07% +60 B 🔺
⛔️ CDN Bundle - uncompressed (max: 84 kB) 84.04 kB +0.13% +107 B 🔺
CDN Bundle (incl. Tracing) - uncompressed 137.95 kB +0.08% +107 B 🔺
CDN Bundle (incl. Logs, Metrics) - uncompressed 88.24 kB +0.18% +157 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 141.41 kB +0.12% +157 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 211.81 kB +0.08% +157 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 255.39 kB +0.05% +107 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 258.84 kB +0.07% +157 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 268.31 kB +0.04% +107 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 271.74 kB +0.06% +157 B 🔺
@sentry/nextjs (client) 48.71 kB +0.1% +48 B 🔺
@sentry/sveltekit (client) 44.39 kB +0.11% +45 B 🔺
@sentry/node-core 58.46 kB +0.2% +115 B 🔺
@sentry/node 175.75 kB +0.06% +99 B 🔺
@sentry/node - without tracing 98.39 kB +0.1% +95 B 🔺
@sentry/aws-serverless 115.4 kB +0.08% +83 B 🔺

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 from 295ad22 to 0886f8b Compare April 22, 2026 14:39
@JPeer264 JPeer264 force-pushed the jp/cloudflare-oom branch from 0886f8b to e945863 Compare April 22, 2026 17:17
Comment thread packages/core/src/instrument/console.ts
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