Commit 5833652
authored
fix(server): await _handleProcessingError so blocking drains surface errors (#579)
# Description
`_processEvents` catches errors from the event-processing loop and
delegates to
`_handleProcessingError`, which — per its own comment — re-throws on the
blocking
path (no `firstResultRejector`) *"so the caller's await catches it"*:
```ts
} catch (error) {
console.error(`Event processing loop failed for task ${taskId}:`, error);
this._handleProcessingError( // <-- not awaited
error, resultManager, firstResultSent, taskId, options?.firstResultRejector,
);
} finally {
eventQueue.stop();
}
```
```ts
// Blocking: re-throw so the caller's await catches it.
if (!firstResultRejector) {
throw error;
}
```
The call is **not awaited**. `_handleProcessingError` is `async`, so its
`throw`
becomes a floating rejection instead of propagating out of
`_processEvents`. The
generator resolves as if the drain had succeeded.
The one blocking caller that passes no `firstResultRejector` is
`cancelTask`'s
drain:
```ts
await this._processEvents(
taskId, new ResultManager(this.taskStore, context), eventQueue, context,
);
```
So when the drain throws (e.g. the task store fails while persisting the
cancellation), `cancelTask` silently swallows the real error, reloads
the task,
sees a non-canceled state, and throws a misleading
`TaskNotCancelableError` —
while the true error surfaces as an unhandled promise rejection.
## Fix
Await `_handleProcessingError`. The blocking re-throw now propagates
through the
`finally` (which still detaches the queue) and out to the awaiting
caller,
matching the documented intent.
The non-blocking paths are unaffected: `sendMessage`/`sendMessageStream`
pass a
`firstResultRejector`, so `_handleProcessingError` rejects or persists a
FAILED
status rather than throwing.
## Tests
Added a regression test asserting `cancelTask` surfaces a drain-time
persistence
error instead of masking it with `TaskNotCancelableError`. Verified it
fails
without the fix (throws `TaskNotCancelableError`) and passes with it.
Full suite green (1368 tests).
- [x] Follows the `CONTRIBUTING` guide
- [x] PR title uses Conventional Commits (`fix:`)
- [x] Tests and linter pass
- [ ] Docs updated (not necessary)1 parent 477e394 commit 5833652
2 files changed
Lines changed: 64 additions & 1 deletion
File tree
- src/server/request_handler
- test/server
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
322 | 322 | | |
323 | 323 | | |
324 | 324 | | |
325 | | - | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
326 | 330 | | |
327 | 331 | | |
328 | 332 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3277 | 3277 | | |
3278 | 3278 | | |
3279 | 3279 | | |
| 3280 | + | |
| 3281 | + | |
| 3282 | + | |
| 3283 | + | |
| 3284 | + | |
| 3285 | + | |
| 3286 | + | |
| 3287 | + | |
| 3288 | + | |
| 3289 | + | |
| 3290 | + | |
| 3291 | + | |
| 3292 | + | |
| 3293 | + | |
| 3294 | + | |
| 3295 | + | |
| 3296 | + | |
| 3297 | + | |
| 3298 | + | |
| 3299 | + | |
| 3300 | + | |
| 3301 | + | |
| 3302 | + | |
| 3303 | + | |
| 3304 | + | |
| 3305 | + | |
| 3306 | + | |
| 3307 | + | |
| 3308 | + | |
| 3309 | + | |
| 3310 | + | |
| 3311 | + | |
| 3312 | + | |
| 3313 | + | |
| 3314 | + | |
| 3315 | + | |
| 3316 | + | |
| 3317 | + | |
| 3318 | + | |
| 3319 | + | |
| 3320 | + | |
| 3321 | + | |
| 3322 | + | |
| 3323 | + | |
| 3324 | + | |
| 3325 | + | |
| 3326 | + | |
| 3327 | + | |
| 3328 | + | |
| 3329 | + | |
| 3330 | + | |
| 3331 | + | |
| 3332 | + | |
| 3333 | + | |
| 3334 | + | |
| 3335 | + | |
| 3336 | + | |
| 3337 | + | |
| 3338 | + | |
3280 | 3339 | | |
3281 | 3340 | | |
3282 | 3341 | | |
| |||
0 commit comments