Skip to content

Commit fa786f7

Browse files
authored
fix: don't drop the live schema while the poller is still running (#107)
afterAll DROP SCHEMA raced Bus.#poll: the poll is two queries with a release between them, and they share a pool of max: 1. DROP in that gap made the events SELECT fail; close() → stop() then surfaced it as a suite failure. Stop the poller first and leave leftover schema for the next setupDb beforeAll. Swallow in-flight poll errors once stop() has already flipped #running.
1 parent 92750fa commit fa786f7

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

src/live/bus.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,13 @@ export class Bus {
312312
#startLoop(): void {
313313
this.#loopPromise = (async () => {
314314
while (this.#running) {
315-
await this.#poll();
315+
try {
316+
await this.#poll();
317+
} catch (e) {
318+
// stop() flipped #running while a poll was in flight (or the
319+
// schema vanished under us). Shutdown is not a poll failure.
320+
if (this.#running) { throw e; }
321+
}
316322
const waiters = this.#oncePolled.splice(0);
317323
for (const w of waiters) {
318324
w();

src/test-helpers.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ export const setupDb = (): void => {
6666
});
6767

6868
afterAll(async () => {
69-
await conn.execute(sql`DROP SCHEMA IF EXISTS ${db.scopedIdent(schema)} CASCADE`);
69+
// Stop the poller first. Don't DROP SCHEMA here — a concurrent poll
70+
// can race the drop (max: 1 pool, two-query poll). Next beforeAll
71+
// already drops leftover schema.
7072
await conn.close();
7173
});
7274
};

0 commit comments

Comments
 (0)