Skip to content

@sentry/cloudflare: The runtime cancels the closing check-in of withMonitor and events in withIsolationScope when the handler returns #25373

Open

Description

@rubas

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/cloudflare

SDK Version

11.7.0

Framework Version

wrangler 4.151.0 (workerd 1.20261012.1)

Link to Sentry event

No response

Reproduction Example/SDK Setup

import * as Sentry from '@sentry/cloudflare';

const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));

export default Sentry.withSentry(() => ({ dsn: 'http://public@127.0.0.1:8969/1' }), {
  async scheduled() {
    await Sentry.withMonitor('foo', () => sleep(20));
  },
  async fetch() {
    await Sentry.withIsolationScope(async () => {
      await sleep(20);
      Sentry.captureMessage('bar');
    });
    return new Response('ok');
  },
} satisfies ExportedHandler);

wrangler.jsonc:

{
  "name": "foo",
  "main": "src/index.ts",
  "compatibility_date": "2026-09-01",
  "compatibility_flags": ["nodejs_compat"]
}

Steps to Reproduce

  1. Start a local ingest on 127.0.0.1:8969. The ingest waits 10 ms before it answers each request. It logs a request as CANCELLED when the client closes the connection before the answer. Ours is a raw TCP server in Bun.
  2. Run wrangler dev --test-scheduled.
  3. Request GET /__scheduled?cron=foo, then GET /fetch/foo.

Expected Result

The ingest receives three envelopes: the in_progress check-in of foo, the ok check-in of foo, and the event bar.

Actual Result

The runtime cancels the closing check-in and the event:

opened 17:00:34.344Z RECEIVED  check_in foo in_progress
opened 17:00:34.365Z CANCELLED at 34.366Z check_in foo ok
opened 17:00:34.995Z CANCELLED at 34.998Z event "bar"

Additional Context

withMonitor, withIsolationScope, trpcMiddleware and wrapMcpServerWithSentry fork the isolation scope. setInvocationState (packages/cloudflare/src/utils/invocationContext.ts) stores the invocation state under a symbol key, and Scope.clone() does not copy it. In the fork, the client sends each envelope at once without waitUntil, and the runtime cancels it when the handler returns.

In 10 scenarios across scheduled, fetch, queue, a Durable Object and a Workflow step, the runtime cancelled 27 of 70 envelopes.

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

  1. linear-code commented on Oct 14, 2026

    @linear-code
  2. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Oct 14, 2026
  3. self-assigned this
    on Oct 15, 2026
  4. JPeer264 commented on Oct 15, 2026

    @JPeer264
    Member

    Thanks for opening the ticket and the PR. I'll take a look at your PR now

  5. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions