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:
parent
3dfac1c3db
commit
e58c80440b
1 changed files with 11 additions and 1 deletions
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Reference in a new issue