@ultimat3/cache 31.22.1 → 31.22.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultimat3/cache",
3
- "version": "31.22.1",
3
+ "version": "31.22.3",
4
4
  "description": "Tagged caching: request memo, LRU, Redis, CDN — one invalidation graph",
5
5
  "keywords": [
6
6
  "ultimate",
@@ -43,6 +43,6 @@
43
43
  "test": "bun test"
44
44
  },
45
45
  "dependencies": {
46
- "@ultimat3/core": "31.22.1"
46
+ "@ultimat3/core": "31.22.3"
47
47
  }
48
48
  }
@@ -185,14 +185,26 @@ export function redisPubSub(options: RedisPubSubOptions): InvalidationBus {
185
185
  }
186
186
  };
187
187
 
188
+ /**
189
+ * The channels THIS connection is subscribed to, replaced on every connect: a new connection
190
+ * holds none, whatever the client still keeps. A set only the lane writes.
191
+ */
192
+ let onConnection = new Set<string>();
193
+
188
194
  /**
189
195
  * `channel` held by exactly one `dispatch`: UNSUBSCRIBE first, because Bun keeps a listener the
190
- * server forgot. In the lane this is idempotent, so a `subscribe` queued behind a resubscribe
191
- * that already covered its channel registers nothing twice.
196
+ * server forgot. A channel this connection already holds is left alone: a boot `subscribe` queued
197
+ * behind the first connect's resubscribe (woken by the publisher's connect) used to UNSUBSCRIBE
198
+ * and SUBSCRIBE it again, and a bust published between the two reached no one (measured: 184 of
199
+ * 300 boots, and `CLIENT LIST TYPE pubsub` no longer listed the replica in that gap).
192
200
  */
193
201
  const subscribeOnce = async (channel: string): Promise<void> => {
202
+ const on = onConnection;
203
+ if (on.has(channel)) return;
194
204
  await unsubscribeQuietly(channel);
195
205
  await bounded('SUBSCRIBE', () => subscriber.subscribe(channel, dispatch));
206
+ // A connect mid-SUBSCRIBE replaced `onConnection`: that answer was the dead connection's.
207
+ on.add(channel);
196
208
  };
197
209
 
198
210
  /** The pending retry's canceller; a reconnect or `close` drops it. */
@@ -225,6 +237,7 @@ export function redisPubSub(options: RedisPubSubOptions): InvalidationBus {
225
237
 
226
238
  // The first connect too: whatever the hop could not publish or subscribe before it is owed now.
227
239
  subscriber.onconnect = () => {
240
+ onConnection = new Set();
228
241
  cancelRetry?.();
229
242
  cancelRetry = undefined;
230
243
  if (!closed) void inLane(() => resubscribe(1));
@@ -270,7 +283,12 @@ export function redisPubSub(options: RedisPubSubOptions): InvalidationBus {
270
283
  held.delete(handler);
271
284
  if (held.size > 0 || handlers.get(subject) !== held) return;
272
285
  handlers.delete(subject);
273
- if (!closed) void inLane(() => unsubscribeQuietly(subject));
286
+ if (!closed) {
287
+ void inLane(() => {
288
+ onConnection.delete(subject);
289
+ return unsubscribeQuietly(subject);
290
+ });
291
+ }
274
292
  },
275
293
  };
276
294
  },