Repository navigation
Commit b8cfdda
fix(cloudflare): Don't hold Durable Object invocations open with the segment-end flush timer (#25490)
Since span streaming became the default (#22642) and segment-end
flushing turned on for server runtimes (#23714), every root span end
schedules `setTimeout(flush, 500)`, sampled or not. #23714 relies on
`safeUnref` to stop that timer holding a server open, but workerd timers
have no `unref()`. A Durable Object invocation stays open until its
pending timers fire, so every instrumented DO `fetch`, alarm,
`webSocketMessage` and propagated RPC call runs about 500 ms longer.
That time is billed as duration, and the pending timer also blocks
hibernation. This happens at `tracesSampleRate: 0` too.
The 500 ms delay comes from the browser (#19643): `http.client` spans
stay open up to 300 ms waiting for resource timing, so they can end
after their segment. Neither that nor the buffer-memory reason for
flushing at segment end on servers (#23714) applies to Workers, where
nothing waits for resource timing and spans are flushed at the end of
every invocation.
The Cloudflare client now registers `spanStreamingIntegration({
flushOnSegmentEnd: false })` unless the user supplies their own. The
runtime doesn't need the timer: the boundary flush in
`wrapMethodWithSentry` runs after the method span ends, and the cached
client's eager drain covers spans that end after the flush point. This
matches the existing `_flushInterval: 0` for the log and metric buffers.
Plain Worker handlers lose the timer too: it doesn't hold their requests
open, so it cost them nothing, but `withSentry`'s boundary flush already
delivers their spans. In workerd, with the same change applied to
11.6.0, DO `fetch` and alarm wall time drops from about 505 ms to about
6 ms, and at `tracesSampleRate: 1.0` the same span envelopes still
arrive.
Fixes #25489
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>1 parent 58cd4f4 commit b8cfdda
2 files changed
Lines changed: 43 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
18 | 23 | | |
19 | 24 | | |
20 | 25 | | |
| |||
59 | 64 | | |
60 | 65 | | |
61 | 66 | | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
62 | 78 | | |
63 | 79 | | |
64 | 80 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
72 | 98 | | |
73 | 99 | | |
74 | 100 | | |
| |||
0 commit comments