[READ-ONLY] Mirror of https://github.com/flo-bit/contrail. atproto backend in a bottle flo-bit.dev/contrail

fix ingest buffer flush while subscription idle master

streamAndFlush only re-checked the flush timer inside the main loop after iterator.next() resolved, so a trickle of events followed by a quiet Jetstream would strand the buffer until the next event or abort. The final flush in the finally block masked the bug in tests that abort. Replace the in-loop flush race with a setInterval-driven periodic flush. The main loop now only races iterator.next() against abort, and flushes are decoupled from loop tempo. Timer-flush errors log and retry next interval rather than propagate — a transient DB hiccup shouldn't force a Jetstream reconnect. Adds a regression test that forces the timer path by setting batchSize well above the event count and asserting records are present BEFORE the controller aborts.


+75 -38
2 changed files