You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Do not dispose client and keep only one client #23083
Every request creates a new client and creating a new client means more overhead for the CPU. This means that after every response we also have to .dispose the client to prevent memory leaks, which brings other downsides as in DOs other async work could potentially be triggered at a later point in time, where the client would be disposed already (see #22545).
Also currently we create a new isolation scope per request, but it wouldn't matter, as there would only be 1 isolation scope in this case.
Solution Brainstorm
Potentially we don't need to create multiple clients, but could reuse a client if it was already created. We would keep the same structure as now but at the time we would create a client, we just need to reuse it. This would solve e.g. #22545 and #21950 as the client wouldn't be disposed.
But it'd bring other challenges, as there is no timer to flush the events (by default we flush after an 5 second interval, which wouldn't work OOTB in Cloudflare as the timing works differently in there). For that we need points in the SDK where we know we can flush. A way I could think of:
flush after every request, as we already do
After the request is done we start listening on events, like afterSpanEnd for spans or afterCaptureLog for logs, so we don't miss out on these, but still have a way to register these events
In the future this could be simplified with tail workers, see #23081
Additional Context
No response
Priority
React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it.
Activity
linear-code commentedon Aug 6, 2026
JS-3292
feat(core): Add `afterEnvelope` and `flushTraceSpans` client hooks (#…
feat(core): Add `afterEnvelope` and `flushTraceSpans` client hooks (#…
feat(cloudflare): Add cacheClient to reuse the client across invocati…
github-actions commentedon Sep 23, 2026
A PR closing this issue has just been released 🚀
This issue was referenced by PR #23151, which was included in the 11.0.0 release.