diff --git a/src/live/bus.ts b/src/live/bus.ts index 90545a9..33b0077 100644 --- a/src/live/bus.ts +++ b/src/live/bus.ts @@ -312,7 +312,13 @@ export class Bus { #startLoop(): void { this.#loopPromise = (async () => { while (this.#running) { - await this.#poll(); + try { + await this.#poll(); + } catch (e) { + // stop() flipped #running while a poll was in flight (or the + // schema vanished under us). Shutdown is not a poll failure. + if (this.#running) { throw e; } + } const waiters = this.#oncePolled.splice(0); for (const w of waiters) { w(); diff --git a/src/test-helpers.ts b/src/test-helpers.ts index 063b383..39e798b 100644 --- a/src/test-helpers.ts +++ b/src/test-helpers.ts @@ -66,7 +66,9 @@ export const setupDb = (): void => { }); afterAll(async () => { - await conn.execute(sql`DROP SCHEMA IF EXISTS ${db.scopedIdent(schema)} CASCADE`); + // Stop the poller first. Don't DROP SCHEMA here — a concurrent poll + // can race the drop (max: 1 pool, two-query poll). Next beforeAll + // already drops leftover schema. await conn.close(); }); };