fix: close delete resume and SSE replay races
This commit is contained in:
@@ -52,9 +52,15 @@ export class SseHub {
|
||||
const subscriber = { send, close: options.close ?? (() => undefined), closed: false };
|
||||
this.subs.get(sessionId)!.add(subscriber);
|
||||
|
||||
const afterId = Number.isSafeInteger(options.afterId) && (options.afterId ?? 0) >= 0
|
||||
const requestedAfterId = Number.isSafeInteger(options.afterId) && (options.afterId ?? 0) >= 0
|
||||
? options.afterId ?? 0
|
||||
: 0;
|
||||
// Native EventSource persists Last-Event-ID across a backend process restart. A cursor newer
|
||||
// than anything this hub generation has produced cannot identify an event in this process,
|
||||
// so replay the fresh generation from its beginning instead of suppressing every low id.
|
||||
const afterId = requestedAfterId > (this.lastIds.get(sessionId) ?? 0)
|
||||
? 0
|
||||
: requestedAfterId;
|
||||
const buf = this.buffers.get(sessionId) ?? [];
|
||||
for (const item of buf) {
|
||||
if (item.id > afterId) send(item.event, item.data, item.id);
|
||||
|
||||
Reference in New Issue
Block a user