Title: Do not dispose client and keep only one client · Issue #23083 · getsentry/sentry-javascript · GitHub
Open Graph Title: Do not dispose client and keep only one client · Issue #23083 · getsentry/sentry-javascript
X Title: Do not dispose client and keep only one client · Issue #23083 · getsentry/sentry-javascript
Description: Problem Statement 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 downside...
Open Graph Description: Problem Statement 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 m...
X Description: Problem Statement 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 m...
Opengraph URL: https://github.com/getsentry/sentry-javascript/issues/23083
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Do not dispose client and keep only one client","articleBody":"### Problem Statement\n\nEvery 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 getsentry/sentry-javascript#22545).\n\nAlso 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.\n\n### Solution Brainstorm\n\nPotentially 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. getsentry/sentry-javascript#22545 and getsentry/sentry-javascript#21950 as the client wouldn't be disposed.\n\nBut 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:\n\n1. flush after every request, as we already do\n2. 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\n\nIn the future this could be simplified with tail workers, see getsentry/sentry-javascript#23081\n\n### Additional Context\n\n*No response*\n\n### Priority\n\nReact with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding `+1` or `me too`, to help us triage it.","author":{"url":"https://github.com/JPeer264","@type":"Person","name":"JPeer264"},"datePublished":"2026-08-06T08:50:07Z","url":"https://github.com/getsentry/sentry-javascript/issues/23083"}
| react-profiling | 0 |
| react-import-map | react,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-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:a03b5a87-5905-c551-0b7c-686d0bdde4c0 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BABA:D1D86:424756:5B1836:6B046EDD |
| html-safe-nonce | 3ba76430591f7bd82d7bc8d0f4cb0901e44a6480eccd3ac23c9fcc1397322829 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQUJBOkQxRDg2OjQyNDc1Njo1QjE4MzY6NkIwNDZFREQiLCJ2aXNpdG9yX2lkIjoiMTMwMjY4ODc2ODM2MDQ3NjM4MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 849a8f2c6e964533bf9e98ecdb8c0a0c0ea3a34bf37a184f9980ae2cbd9548f2 |
| hovercard-subject-tag | issue:5079401928 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/getsentry/sentry-javascript/23083/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e5377719981172430e7d2a6e6477d5315595adfbc4bc0838d9e8ff07c4777268/getsentry/sentry-javascript/issues/23083 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e5377719981172430e7d2a6e6477d5315595adfbc4bc0838d9e8ff07c4777268/getsentry/sentry-javascript/issues/23083 |
| og:image:alt | Problem Statement 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 m... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | JPeer264 |
| hostname | github.com |
| expected-hostname | github.com |
| None | ae8802492f12d3ba4f6b0d814054e617a2a5616b6327bf8555c10cd5b0dc2a6f |
| turbo-cache-control | no-preview |
| go-import | github.com/getsentry/sentry-javascript git https://github.com/getsentry/sentry-javascript.git |
| octolytics-dimension-user_id | 1396951 |
| octolytics-dimension-user_login | getsentry |
| octolytics-dimension-repository_id | 3328572 |
| octolytics-dimension-repository_nwo | getsentry/sentry-javascript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 3328572 |
| octolytics-dimension-repository_network_root_nwo | getsentry/sentry-javascript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | cfb5f24c6e01d85f70804652a5107e5cac03a161 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width