Closed
Description
Hi,
Starting v3.3.0
, if I have multiple listeners bound to the same event, and the DB connection is interrupted, only the latest listener will successfully reconnect & get triggered for new notify
events. Additionally, the listener.state
value is missing for all listeners after the first one. Here's a minimal reproduction that works as expected with v3.2.4
but breaks from v3.3.0
import postgres from "postgres";
import { setTimeout } from "node:timers/promises";
const sql = postgres();
const listener1 = await sql.listen(
"jobs",
(x) => console.log(`listener1 got payload: "${x}"`),
() => console.log(`listener1 onlisten()`)
);
const listener2 = await sql.listen(
"jobs",
(x) => console.log(`listener2 got payload: "${x}"`),
() => console.log(`listener2 onlisten()`)
);
const listener3 = await sql.listen(
"jobs",
(x) => console.log(`listener3 got payload: "${x}"`),
() => console.log(`listener3 onlisten()`)
);
console.log("notify j1", { l1: listener1.state, l2: listener2.state, l3: listener3.state });
sql.notify("jobs", "j1");
await setTimeout(100);
// Terminate one of the listeners
console.log("terminating listener1");
await sql`select pg_terminate_backend(${listener1.state.pid})`;
await setTimeout(100); // give time to reconnect
// Trigger another event
console.log("notify j2", { l1: listener1.state, l2: listener2.state, l3: listener3.state });
sql.notify("jobs", "j2");
await setTimeout(800);
await sql.end();
Metadata
Metadata
Assignees
Labels
No labels