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
2 changed files with 11 additions and 1 deletions
|
|
@ -138,9 +138,12 @@ describe("primeAndHoldSseStream (#1999)", () => {
|
|||
|
||||
s.finishWrite();
|
||||
s.abort();
|
||||
// Hono guards re-entry itself, but the helper must not depend on that —
|
||||
// so drive the listener a second time directly.
|
||||
s.abort();
|
||||
await withinTick(held);
|
||||
// Hono guards re-entry itself, but the helper must not depend on that.
|
||||
expect(cleanups).toBe(1);
|
||||
expect(s.closes).toBe(1);
|
||||
});
|
||||
|
||||
it("does not reject when cleanup's own close loses the race", async () => {
|
||||
|
|
|
|||
|
|
@ -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