fix: guard the abort listener against a double invocation

Copilot review round 1. The helper's contract is exactly-once teardown
and the test asserted it must not lean on Hono's own re-entry guard, but
neither the implementation nor the test actually enforced that: the
listener had no local guard and the test aborted only once.

Signed-off-by: cliffhall <cliff@futurescale.com>
This commit is contained in:
cliffhall 2026-08-17 14:41:24 -04:00
commit e58c80440b

View file

@ -147,8 +147,15 @@ export async function primeAndHoldSseStream(
stream: PrimableSseStream,
cleanup: () => void,
): Promise<void> {
let done = false;
const aborted = new Promise<void>((resolve) => {
stream.onAbort(() => {
// Hono's `abort()` guards its own re-entry, but the guard belongs here
// too: this helper's contract is exactly-once teardown, and running a
// caller's cleanup twice would double-delete a subscriber that has
// since been re-added by a reconnect.
if (done) return;
done = true;
cleanup();
closeAbortedStream(stream);
resolve();