Commit 645042d
committed
fix(request): reject before onTimeout so stream stalls fail instead of ending cleanly
withTimeout invoked onTimeout before rejecting. forwardStreamingResponse's
onTimeout cancels the stream reader, and cancelling settles the pending
read() with {done: true} ahead of the rejection in the microtask queue, so
Promise.race resolved: a stalled upstream stream was forwarded to the
client as a clean end-of-stream — truncated body with a normal end(), no
status.lastError, and the onStreamError failover hook never fired. The
stall branch of the catch block was unreachable.
Rejecting first enqueues the race's rejection ahead of any settlement the
onTimeout side effects can cause, restoring the intended stall handling:
the response is destroyed, lastError records the stall, and onStreamError
fires. readErrorBody (the only other caller) uses a no-op onTimeout and is
unaffected.
The regression test pinning the old behavior is flipped to the intended
expectations and documents the mechanism.
https://claude.ai/code/session_01XNtnkLbBiXZxfQQYLMpucB1 parent 4d5dd51 commit 645042d
2 files changed
Lines changed: 17 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
52 | 55 | | |
| 56 | + | |
53 | 57 | | |
54 | 58 | | |
55 | 59 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
232 | 232 | | |
233 | 233 | | |
234 | 234 | | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
243 | 241 | | |
244 | 242 | | |
245 | 243 | | |
| |||
250 | 248 | | |
251 | 249 | | |
252 | 250 | | |
253 | | - | |
| 251 | + | |
254 | 252 | | |
255 | | - | |
256 | | - | |
257 | | - | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
258 | 257 | | |
259 | | - | |
| 258 | + | |
260 | 259 | | |
261 | 260 | | |
262 | 261 | | |
| |||
0 commit comments