Skip to content

fix(cloudflare): avoid repeated flush lock wrapping#21156

Open
logaretm wants to merge 2 commits into
developfrom
awad/js-2605-makeflushlock-grows-a-waituntil-wrapper-chain-on-every-init
Open

fix(cloudflare): avoid repeated flush lock wrapping#21156
logaretm wants to merge 2 commits into
developfrom
awad/js-2605-makeflushlock-grows-a-waituntil-wrapper-chain-on-every-init

Conversation

@logaretm
Copy link
Copy Markdown
Member

@logaretm logaretm commented May 25, 2026

Durable Objects can reuse the same instrumented context across many requests. makeFlushLock() replaced context.waitUntil on every init, so each request wrapped the previous wrapper and built an unbounded call chain.

A later waitUntil() call then had to recurse through every wrapper, eventually causing stack overflows and retaining stale closures.

I added a mechanism to reuse a single waitUntil wrapper per Cloudflare context instead of wrapping again on every SDK init. Also added a regression coverage for long-lived contexts repeatedly creating flush locks.

Fixes #21150

@linear-code
Copy link
Copy Markdown

linear-code Bot commented May 25, 2026

JS-2605

@logaretm logaretm changed the title test(cloudflare): reproduce flush lock wrapper growth fix(cloudflare): avoid repeated flush lock wrapping May 25, 2026
@logaretm logaretm marked this pull request as ready for review May 25, 2026 11:01
@logaretm logaretm requested a review from a team as a code owner May 25, 2026 11:01
@logaretm logaretm requested review from JPeer264 and andreiborza and removed request for a team May 25, 2026 11:01
@github-actions
Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 27.32 kB - -
@sentry/browser - with treeshaking flags 25.74 kB - -
@sentry/browser (incl. Tracing) 45.31 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 47.55 kB - -
@sentry/browser (incl. Tracing, Profiling) 50.3 kB - -
@sentry/browser (incl. Tracing, Replay) 84.92 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 74.43 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 89.64 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 102.24 kB - -
@sentry/browser (incl. Feedback) 44.51 kB - -
@sentry/browser (incl. sendFeedback) 32.13 kB - -
@sentry/browser (incl. FeedbackAsync) 37.25 kB - -
@sentry/browser (incl. Metrics) 28.41 kB - -
@sentry/browser (incl. Logs) 28.64 kB - -
@sentry/browser (incl. Metrics & Logs) 29.33 kB - -
@sentry/react 29.05 kB - -
@sentry/react (incl. Tracing) 47.55 kB - -
@sentry/vue 32.24 kB - -
@sentry/vue (incl. Tracing) 47.17 kB - -
@sentry/svelte 27.35 kB - -
CDN Bundle 29.73 kB - -
CDN Bundle (incl. Tracing) 47.84 kB - -
CDN Bundle (incl. Logs, Metrics) 31.21 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 49.09 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 70.53 kB - -
CDN Bundle (incl. Tracing, Replay) 85.34 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 86.5 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 91.2 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.37 kB - -
CDN Bundle - uncompressed 87.8 kB - -
CDN Bundle (incl. Tracing) - uncompressed 144.29 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 92.29 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 148.05 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 217.02 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 263.07 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 266.81 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 276.77 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 280.5 kB - -
@sentry/nextjs (client) 50.03 kB - -
@sentry/sveltekit (client) 45.8 kB - -
@sentry/core/server 76.48 kB - -
@sentry/core/browser 63.23 kB - -
@sentry/node-core 62.59 kB +0.01% +2 B 🔺
@sentry/node 131.1 kB - -
@sentry/node - without tracing 75.02 kB - -
@sentry/aws-serverless 87.24 kB - -
@sentry/cloudflare (withSentry) - minified 173.52 kB +0.23% +390 B 🔺
@sentry/cloudflare (withSentry) 433.52 kB +0.26% +1.09 kB 🔺

View base workflow run

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.

makeFlushLock grows a waitUntil wrapper chain on every init(), causing stack overflow and memory exhaustion in Durable Objects

1 participant