Repository navigation
Commit 0e38bd8
fix(publisher): isolate listener errors in Upstash and memory adapters (#2375)
## Problem
**Upstash adapter.** A subscriber whose `onError` throws breaks delivery
for every other subscriber on the channel:
- `@upstash/redis` calls the `message` handler inside its own try/catch
and re-emits any throw as an `error` event.
- The adapter forwards `error` events to every registered `onError`, so
the error is broadcast to all of them.
- Iterator subscribers terminate on `onError`.
- The throw also stops delivery to the remaining listeners for that
message.
**Memory adapter.** `publish()` calls listeners with no try/catch, so
one throwing listener stops delivery to later subscribers and rejects
`publish()`. The Redis and Durable adapters already isolate per-listener
errors.
## Changes
- **Upstash:** each listener call in message dispatch is wrapped in
`tryOrUndefined`, so a throw neither reaches Upstash nor stops the other
listeners. Listeners already send their own failures to `onError` in
`BaseRedisPublisher`, so in practice this guards against an `onError`
that throws.
- **Memory:** each listener is wrapped at subscribe time, and a throw
goes to that subscriber's `onError`.
## Tests
- **Upstash:** a credential-free fake-client test mimics how Upstash
re-emits a handler throw as `error`. It checks that a second subscriber
still receives the message and that its `onError` is not called.
- **Memory:** a test checks that a throwing listener doesn't stop
delivery or reject `publish()`.
Both tests fail without the fix. `pnpm vitest run packages/publisher`,
`pnpm type:check` and `pnpm lint` pass.
## Not in this PR
- **Silent stream drops:** `@upstash/redis` never reports that an
established stream has dropped. `command.exec()` resolves once the SSE
response headers arrive, and the body is read in a detached task that
only logs read failures with `console.error`. So a dropped stream stays
in `subscriptionMap` unnoticed. Detecting that needs either a liveness
check or an upstream change, and is left for a follow-up.
- **Other adapters:** they still isolate listener errors in their own
ways.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01VVaw7Pcdx6NZtoSRJNFXRZ
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent f59a986 commit 0e38bd8
4 files changed
Lines changed: 74 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
284 | 284 | | |
285 | 285 | | |
286 | 286 | | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
287 | 307 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
| |||
77 | 78 | | |
78 | 79 | | |
79 | 80 | | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
80 | 90 | | |
81 | 91 | | |
82 | 92 | | |
83 | 93 | | |
84 | 94 | | |
85 | | - | |
| 95 | + | |
86 | 96 | | |
87 | 97 | | |
88 | 98 | | |
89 | 99 | | |
90 | | - | |
| 100 | + | |
91 | 101 | | |
92 | 102 | | |
93 | 103 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
706 | 706 | | |
707 | 707 | | |
708 | 708 | | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
106 | | - | |
| 106 | + | |
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
| |||
0 commit comments