Title: `@sentry/cloudflare` v11: every instrumented Durable Object invocation stays open ~500 ms after it finishes (span streaming's segment-end timer, even when unsampled) · Issue #25489 · getsentry/sentry-javascript · GitHub
Open Graph Title: `@sentry/cloudflare` v11: every instrumented Durable Object invocation stays open ~500 ms after it finishes (span streaming's segment-end timer, even when unsampled) · Issue #25489 · getsentry/sentry-javascript
X Title: `@sentry/cloudflare` v11: every instrumented Durable Object invocation stays open ~500 ms after it finishes (span streaming's segment-end timer, even when unsampled) · Issue #25489 · getsentry/sentry-javascript
Description: Is there an existing issue for this? I have checked for existing issues How do you use Sentry? Sentry SaaS (sentry.io) Which SDK are you using? @sentry/cloudflare SDK Version 11.0.0 through 11.8.0 (measured on 11.6.0; the code is unchang...
Open Graph Description: Is there an existing issue for this? I have checked for existing issues How do you use Sentry? Sentry SaaS (sentry.io) Which SDK are you using? @sentry/cloudflare SDK Version 11.0.0 through 11.8.0 ...
X Description: Is there an existing issue for this? I have checked for existing issues How do you use Sentry? Sentry SaaS (sentry.io) Which SDK are you using? @sentry/cloudflare SDK Version 11.0.0 through 11.8.0 ...
Opengraph URL: https://github.com/getsentry/sentry-javascript/issues/25489
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`@sentry/cloudflare` v11: every instrumented Durable Object invocation stays open ~500 ms after it finishes (span streaming's segment-end timer, even when unsampled)","articleBody":"### Is there an existing issue for this?\n\n- [x] I have checked for existing issues\n\n### How do you use Sentry?\n\nSentry SaaS (sentry.io)\n\n### Which SDK are you using?\n\n`@sentry/cloudflare`\n\n### SDK Version\n\n11.0.0 through 11.8.0 (measured on 11.6.0; the code is unchanged in 11.0.0 and 11.8.0). 10.76.2 is unaffected.\n\n### Framework Version\n\nwrangler 4.148.0 / workerd 1.20261006.1, `compatibility_date: 2025-08-13`, `nodejs_compat`. Production shows the same thing: our alarm median went from about 25 ms on 10.76.2 to 505 ms on 11.6.0.\n\n### Link to Sentry event\n\nN/A\n\n### Reproduction Example/SDK Setup\n\nThe options are the ones from the [Wrangler setup docs](https://docs.sentry.io/platforms/javascript/guides/cloudflare/install/wrangler/). The DSN can be fake: nothing is sent at `tracesSampleRate: 0`.\n\n```js\nimport { DurableObject } from 'cloudflare:workers';\nimport * as Sentry from '@sentry/cloudflare';\n\nconst options = (env) => ({ dsn: env.SENTRY_DSN, tracesSampleRate: 0 }); // the docs use 1.0; any rate reproduces\n\nclass Base extends DurableObject {\n\tasync fetch(request) {\n\t\tif (new URL(request.url).searchParams.has('alarm')) await this.ctx.storage.setAlarm(Date.now() + 50);\n\t\treturn new Response('ok');\n\t}\n\tasync alarm() {}\n\tasync ping() {\n\t\treturn 'pong';\n\t}\n}\n\nexport const MyDO = Sentry.instrumentDurableObjectWithSentry(options, Base);\n\nexport default Sentry.withSentry((env) => ({ ...options(env), rpcTracePropagationBindings: ['MyDO'] }), {\n\tasync fetch(request, env) {\n\t\tconst stub = env.MyDO.get(env.MyDO.idFromName(crypto.randomUUID()));\n\t\tif (new URL(request.url).searchParams.has('rpc')) return new Response(await stub.ping());\n\t\treturn stub.fetch(request);\n\t},\n});\n```\n\nI measured invocation duration with a tail consumer, as the time from `eventTimestamp` to the tail event's arrival. In production, use `wallTimeMs` in Workers Logs.\n\n### Steps to Reproduce\n\n1. Run the Worker with `wrangler dev`, or deploy it.\n2. Call it plain (DO `fetch`), with `?rpc` (DO RPC) and with `?alarm` (alarm).\n3. Compare each invocation's wall time with the same code on 10.76.2.\n\n### Expected Result\n\nEach invocation's wall time matches its handler's duration, as it does on 10.x.\n\n### Actual Result\n\nEvery Durable Object invocation that creates a span stays open for about 500 ms after the handler returns. That covers `fetch`, `alarm`, `webSocketMessage`, and RPC methods when trace metadata is propagated. (`webSocketClose` measured 0–1 ms, so I have left it out.) The 500 ms is added on top of the handler, not a minimum: a 1 s alarm takes 1.5 s. The hold ends early if another event reaches the same object first. CPU time is unchanged.\n\nDurable Objects are billed for wall-clock duration, and the pending timer also blocks hibernation. So each burst of activity costs up to 500 ms of extra billed time, and a hibernating WebSocket object stays awake for 500 ms after every message.\n\nWall time per invocation. Each variant ran in its own Worker (the client is cached per isolate, so variants sharing a Worker leak options into each other); two to three runs each:\n\n| Invocation | No Sentry | 10.76.2 | **11.6.0** | 11.6.0 `traceLifecycle: 'static'` |\n| --------------------------------------------------------- | --------- | ------------ | ---------------- | --------------------------------- |\n| DO `fetch` | 3 ms | 4–6 ms | **506 ms** | 4 ms |\n| DO alarm (no-op) | 2–3 ms | 6 ms | **504–508 ms** | 5–12 ms |\n| DO alarm (handler sleeps 1 s) | 1006 ms | 1007–1010 ms | **1507–1508 ms** | 1007–1009 ms |\n| DO `webSocketMessage` (hibernation API) | 0–8 ms | 2–6 ms | **503–504 ms** | 3–5 ms |\n| DO RPC, caller propagates (`rpcTracePropagationBindings`) | – | – | **504–505 ms** | – |\n| DO RPC, no propagation (no span is created) | 1–2 ms | 1–2 ms | 4 ms | 4–5 ms |\n| DO `fetch` followed by an alarm 50 ms later | 4–6 ms | 5 ms | 53–54 ms | 6–9 ms |\n| Stateless Worker `fetch` (`withSentry`) | 3–18 ms | 5–23 ms | 4–14 ms | 11–16 ms |\n\nControls: a handler with no Sentry that leaves its own `setTimeout(() => {}, 500)` pending shows the same 505 ms. With `tracesSampleRate` unset (tracing off), 11.6.0 shows no hold. `spanStreamingIntegration({ flushOnSegmentEnd: false })` removes it, as does `traceLifecycle: 'static'`. `cacheClient: false` does not help.\n\n### Additional Context\n\nCause:\n\n1. In v11, `Client` defaults `traceLifecycle` to `'stream'` (#22642), and `ServerRuntimeClient` adds `spanStreamingIntegration()`.\n2. Since #23714, that integration runs `safeUnref(setTimeout(() => buffer.flush(traceId), 500))` on every `afterSegmentSpanEnd`.\n3. An unsampled root span is still a `SentrySpan`, and ending it still emits `afterSegmentSpanEnd`. The timer is therefore scheduled at `tracesSampleRate: 0` too, and it flushes an empty buffer.\n4. #23714 says the server-side event-loop concern \"is already handled by `safeUnref` on the timer\". workerd timers have no `unref()`, though. A Durable Object invocation stays open until its pending timers fire, and Cloudflare's [lifecycle docs](https://developers.cloudflare.com/durable-objects/concepts/durable-object-lifecycle/) say pending `setTimeout` timers prevent hibernation and eviction and incur duration charges. Stateless Worker requests don't wait for timers, which is why only Durable Objects show this.\n\nOn Cloudflare the timer is redundant even when spans are sampled. In v11, `wrapMethodWithSentry` runs its teardown flush after the method span has ended. That flush emits `flush`, which drains the `SpanBuffer`. The 500 ms timer is never cleared, so it outlives the drain.\n\nThe delay was built for the browser (#19643): `http.client` spans stay open up to 300 ms waiting for resource timing, so they can end after their segment. #23714 then turned segment-end flushing on for servers too, so the 5 s buffer wouldn't build up memory under high throughput. Neither reason applies on Workers: nothing waits for resource timing, and spans are already flushed at the end of every invocation.\n\nThe timer is also invisible from user code, so the only symptom is wall time pinned about 500 ms above CPU time.\n\nPossible fixes:\n\n- `@sentry/cloudflare` registers `spanStreamingIntegration({ flushOnSegmentEnd: false })` by default, since the boundary flush and `flushTraceSpans` already deliver the spans.\n- The integration skips the segment-end timer for unsampled segment spans, and for traces the buffer no longer holds.\n- The Durable Object docs mention `traceLifecycle: 'static'` until a fix ships.\n\nWorkaround: pass `traceLifecycle: 'static'` (or set `SENTRY_TRACE_LIFECYCLE=static`), or leave `tracesSampleRate` unset if you don't need tracing.\n","author":{"url":"https://github.com/philipatkinson","@type":"Person","name":"philipatkinson"},"datePublished":"2026-10-18T14:47:15Z","url":"https://github.com/getsentry/sentry-javascript/issues/25489"}
| 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:d8a07455-f278-a6fc-5798-b1444e368b9c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B730:30AFC6:DF9C2:139840:6B042A93 |
| html-safe-nonce | 70b46fc23e19f6d871fc780780f7fd4bd4c36c73e416976a3b81e655a8dff9e8 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNzMwOjMwQUZDNjpERjlDMjoxMzk4NDA6NkIwNDJBOTMiLCJ2aXNpdG9yX2lkIjoiNDA0NjI3NTQ3NTc0MjY2NTM2MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 65e648b56705c6de206bc7dc7a07f8f0711895763af9047babb7466e97d7681c |
| hovercard-subject-tag | issue:5910727387 |
| 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/25489/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e5372e798083ad70320cce1cab4a7900d8d0c5b157b43770d70775c305577501/getsentry/sentry-javascript/issues/25489 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e5372e798083ad70320cce1cab4a7900d8d0c5b157b43770d70775c305577501/getsentry/sentry-javascript/issues/25489 |
| og:image:alt | Is there an existing issue for this? I have checked for existing issues How do you use Sentry? Sentry SaaS (sentry.io) Which SDK are you using? @sentry/cloudflare SDK Version 11.0.0 through 11.8.0 ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | philipatkinson |
| hostname | github.com |
| expected-hostname | github.com |
| None | b7a1d2b9101496921b08579fbee988d014345aef2f5bd660d1f8c7332d81560e |
| 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 | c3dd496c3da6ea6b77e69c09279d2b81604654f1 |
| 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