Title: [cloudflare] scheduled handler: raw `waitUntil(flushAndDispose(client))` fails every cron invocation with silent outcome=exception · Issue #21950 · getsentry/sentry-javascript · GitHub
Open Graph Title: [cloudflare] scheduled handler: raw `waitUntil(flushAndDispose(client))` fails every cron invocation with silent outcome=exception · Issue #21950 · getsentry/sentry-javascript
X Title: [cloudflare] scheduled handler: raw `waitUntil(flushAndDispose(client))` fails every cron invocation with silent outcome=exception · Issue #21950 · getsentry/sentry-javascript
Description: Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using the latest SDK release https://github.com/...
Open Graph Description: Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using th...
X Description: Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using th...
Opengraph URL: https://github.com/getsentry/sentry-javascript/issues/21950
X: @github
Domain: github.com
IPv4 address: 140.82.113.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[cloudflare] scheduled handler: raw `waitUntil(flushAndDispose(client))` fails every cron invocation with silent outcome=exception","articleBody":"### Is there an existing issue for this?\n\n- [X] I have checked for existing issues [https://github.com/getsentry/sentry-javascript/issues](\u003chttps://github.com/getsentry/sentry-javascript/issues>)\n- [X] I have reviewed the documentation [https://docs.sentry.io/](\u003chttps://docs.sentry.io/>)\n- [X] I am using the latest SDK release [https://github.com/getsentry/sentry-javascript/releases](\u003chttps://github.com/getsentry/sentry-javascript/releases>)\n\n### How do you use Sentry?\n\nSentry Saas ([sentry.io](\u003chttp://sentry.io>))\n\n### Which SDK are you using?\n\n@sentry/cloudflare\n\n### SDK Version\n\n10.53.1\n\n### Framework Version\n\nCloudflare Workers (Hono app, `withSentry` wrapper), scheduled handler via cron trigger\n\n### Link to Sentry event\n\n*(none — the failure mode is precisely that no event and no log is produced)*\n\n### Reproduction Example/SDK Setup\n\n```ts\nexport default Sentry.withSentry(\n (env) => ({ dsn: env.SENTRY_DSN, release: env.RELEASE, tracesSampleRate: 0 }),\n {\n fetch: app.fetch,\n scheduled: myScheduledHandler, // ← every tick reports outcome=exception\n } satisfies ExportedHandler\u003cBindings>,\n);\n```\n\n### Steps to Reproduce\n\nWe could **not** build a minimal repro — `wrangler dev` and remote preview never exhibit it. It only manifested in the production isolate, with concurrent fetch traffic hitting the same Worker. Filing anyway because the code path is visible by inspection and our elimination evidence is strong; happy to run instrumented builds if it helps.\n\n1. Worker wrapped in `withSentry` with both `fetch` and `scheduled` handlers, cron trigger every minute.\n2. In production, every single cron tick reports `outcome: exception` in the Cloudflare dashboard and in `wrangler tail --format json`.\n3. Nothing is thrown from user code: no log lines, no Sentry event, no exception payload in the tail JSON — the handler body demonstrably runs to completion (its side effects are all applied).\n\n### Expected Result\n\nA failure inside the SDK's own post-handler flush must not fail the invocation. `wrapScheduledHandler` should never let its housekeeping reject the `waitUntil` promise:\n\n```js\n// instrumentations/worker/instrumentScheduled.js\n} finally {\n waitUntil(flushAndDispose(client).catch(() => {\n DEBUG_BUILD && debug.warn('Failed to flush/dispose in scheduled handler');\n }));\n}\n```\n\n(Or make `flushAndDispose` itself never-reject — every wrapper call site passes it raw: `instrumentScheduled.js`, `instrumentQueue.js`, `instrumentEmail.js`, `instrumentTail.js`, and the five `waitUntil?.(flushAndDispose(client))` sites in `request.js`.)\n\n### Actual Result\n\nIn `@sentry/cloudflare@10.53.1`, `wrapScheduledHandler` does:\n\n```js\n} finally {\n waitUntil(flushAndDispose(client));\n}\n```\n\nwith\n\n```js\nasync function flushAndDispose(client, timeout = 2000) {\n ...\n await client.flush(timeout);\n client.dispose();\n}\n```\n\nOn Workers, a **rejected promise passed to** `ctx.waitUntil` **fails the whole invocation** — the runtime records `outcome: exception` even though the handler returned normally. For a fetch handler this is mostly invisible (the response already went out); for a **cron** it flips every tick to \"failed\" in the dashboard, silently: the rejection happens after user code, so nothing is loggable from the app and the SDK (whose transport just failed / whose client is mid-dispose) can't report its own demise.\n\n**Elimination evidence** from our production incident:\n\n* Every cron tick = `outcome: exception`, zero logs, zero exceptions in tail JSON, handler side effects all present.\n* Three consecutive releases added progressively more defensive guards **inside our handler** (whole-body try/catch, guarded resource teardown so nothing user-side could reject) — no effect whatsoever.\n* Moving `scheduled` **outside** `withSentry` (keeping our own direct envelope delivery for errors) fixed it instantly: same handler code, `outcome: ok` on every tick since, across weeks.\n\nWe did not manage to capture the underlying rejection value (by nature it never surfaces anywhere we can hook). Plausible candidates are `client.flush()` rejecting when the isolate's subrequest is canceled at teardown, or `dispose()` throwing on an already-disposed client under concurrent invocations sharing the isolate — possibly related to the client-lifetime issues in getsentry/sentry-javascript#20533 and getsentry/sentry-javascript#19589, but the failure mode here is different: the *invocation itself* is marked failed by the raw `waitUntil`.\n\nOur current workaround is keeping the scheduled handler unwrapped, which means losing `faas.cron` spans and automatic capture for crons — we'd love to re-wrap once the flush is guarded.","author":{"url":"https://github.com/aabrius","@type":"Person","name":"aabrius"},"datePublished":"2026-07-03T09:01:50Z","url":"https://github.com/getsentry/sentry-javascript/issues/21950"}
| 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:fce9e042-66d8-9456-d76b-a6b94a8017f7 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B354:D405E:344F5CD:4458C83:6B0433A4 |
| html-safe-nonce | 5332c9709c3f4e7546acc08af33b6b74b6c085006b96b9feb79ae37260f41492 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMzU0OkQ0MDVFOjM0NEY1Q0Q6NDQ1OEM4Mzo2QjA0MzNBNCIsInZpc2l0b3JfaWQiOiI1Njg4OTAxMDU5NzIxMDQ4OTk2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | a5bd77124a485f5740a040b1793eb02226590d8153c67fe0ebcc60a5741d909e |
| hovercard-subject-tag | issue:4802049612 |
| 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/21950/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f4ccaa87d2b65119613460ab1a08d0aa0495a61fe7c6a6e2c169ce0155787fc4/getsentry/sentry-javascript/issues/21950 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f4ccaa87d2b65119613460ab1a08d0aa0495a61fe7c6a6e2c169ce0155787fc4/getsentry/sentry-javascript/issues/21950 |
| og:image:alt | Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using th... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | aabrius |
| 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