Read reports: a report that throws no longer wedges its room
The per-room tail was chained with .then(run), so a rejected run skipped every later report for that room and left the cleanup as an unhandled rejection. Chain on both outcomes and clean up on both. A test reaches it with a presence failure plus a throwing logger and fails on the old chain. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
62c1d4e0f1
commit
7e258988e5
2 changed files with 20 additions and 2 deletions
|
|
@ -1285,3 +1285,21 @@ test("chat_read round-trips and refuses a malformed tuple", () => {
|
|||
assert.throws(() => docs.parseRead(["eureka", "#r", "$e", -1]), /at_unix_ms/);
|
||||
assert.throws(() => docs.parseRead(["eureka", "#r", "$e"]));
|
||||
});
|
||||
|
||||
test("a read report that throws does not wedge the room: the next report still posts and nothing is left unhandled", async () => {
|
||||
const hs = await fakeHomeserver({ sync: receiptScript });
|
||||
let boom = false;
|
||||
const fetch = (url, init) => boom && String(url).includes("/presence/") ? Promise.reject(new Error("net")) : hs.fetch(url, init);
|
||||
const mouth = await withMail(hs, { fetch, log: line => { if (boom && line.startsWith("presence not set")) throw new Error("logger down"); } }); // the presence failure and a throwing logger make run() reject
|
||||
const unhandled = [], note = error => unhandled.push(String(error));
|
||||
process.on("unhandledRejection", note);
|
||||
try {
|
||||
boom = true;
|
||||
await assert.rejects(reportRead(mouth, A, "$a1"), /logger down/);
|
||||
boom = false;
|
||||
assert.equal(await reportRead(mouth, A, "$a2"), null, "the room's next report is judged and posted");
|
||||
await new Promise(resolve => setTimeout(resolve, 50));
|
||||
} finally { process.off("unhandledRejection", note); }
|
||||
assert.deepEqual(unhandled, [], "no rejection escapes the tail's cleanup");
|
||||
assert.equal(hs.receipts().length, 1);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -409,9 +409,9 @@ export function createMouth({
|
|||
readThrough.set(known.roomId, { seq: known.seq, eventId });
|
||||
return null;
|
||||
};
|
||||
const tail = (readTails.get(known.roomId) ?? Promise.resolve()).then(run);
|
||||
const tail = (readTails.get(known.roomId) ?? Promise.resolve()).then(run, run); // a report that threw must not wedge the room's later ones
|
||||
readTails.set(known.roomId, tail);
|
||||
tail.then(() => { if (readTails.get(known.roomId) === tail) readTails.delete(known.roomId); });
|
||||
tail.then(() => { if (readTails.get(known.roomId) === tail) readTails.delete(known.roomId); }, () => { if (readTails.get(known.roomId) === tail) readTails.delete(known.roomId); });
|
||||
return tail;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue