fix(readers): never replay a failed read decision; bound the recent-reads map
Build & push images / images (push) Successful in 3m3s
Build & push images / images (push) Successful in 3m3s
Follow-up to ec01591. A first decision that threw was cached and replayed
to repeats inside the window, and the telemetry hook on it had no rejection
handler, so one throwing flow became an unhandled rejection per repeat. A
failed decision is now forgotten (the next read decides afresh) and the
hook handles rejection. The recent-reads map prunes above 512 entries and
never exceeds 4096, whatever a misbehaving reader sends.
This commit is contained in:
@@ -110,6 +110,34 @@ describe("read-dispatch same-code debounce", () => {
|
||||
expect(ledger()).toHaveLength(2);
|
||||
});
|
||||
|
||||
it("a FAILED first decision is not replayed: the repeat decides afresh, no unhandled rejection", async () => {
|
||||
seed({});
|
||||
// Make the exit flow blow up once (e.g. a signer hiccup), then work.
|
||||
const log = makeLog(db);
|
||||
const flaky = new ExitFlow(db, log, silentLogger());
|
||||
let calls = 0;
|
||||
const orig = flaky.handleAt.bind(flaky);
|
||||
flaky.handleAt = async (...args: Parameters<ExitFlow["handleAt"]>) => {
|
||||
calls++;
|
||||
if (calls === 1) throw new Error("signer busy");
|
||||
return orig(...args);
|
||||
};
|
||||
const d2 = new ReadDispatcher(db, flaky, new SubscriptionFlow(db, log, silentLogger()), silentLogger());
|
||||
const rejections: unknown[] = [];
|
||||
const onUnhandled = (r: unknown) => rejections.push(r);
|
||||
process.on("unhandledRejection", onUnhandled);
|
||||
try {
|
||||
await expect(d2.dispatch(read("00000000000"))).rejects.toThrow("signer busy");
|
||||
const second = await d2.dispatch(read("00000000000")); // inside the window, but nothing to replay
|
||||
expect(second.accepted).toBe(false); // a real decision (refused: no session), signed once
|
||||
expect(ledger()).toHaveLength(1);
|
||||
await new Promise((r) => setTimeout(r, 10));
|
||||
expect(rejections).toEqual([]);
|
||||
} finally {
|
||||
process.off("unhandledRejection", onUnhandled);
|
||||
}
|
||||
});
|
||||
|
||||
it("a repeat arriving while the first read is still deciding gets the SAME decision", async () => {
|
||||
const d = seed({});
|
||||
const [a, b] = await Promise.all([d.dispatch(read("00000000000")), d.dispatch(read("00000000000"))]);
|
||||
|
||||
Reference in New Issue
Block a user