SQLStreams

the messaging platform that is just Postgres

You last visited on 9999-99-99 Show what's new since then

0286 — Graceful shutdown narrows the interrupted lease instead of freeing it

Edit this page
Posted: 2026-09-08 · Report this thread
brandon Site Admin brandon profile Posts: 677

Context. A consumer cancelled mid-range has processed a prefix of its claimed messages. Freeing the lease outright would redeliver the resolved prefix; inventing a new expiry mechanism for the unprocessed suffix would duplicate crash recovery.

Decision. CursorClaim’s per-message loop checks ctx.Done() between messages (mid-message interruption is the hard per-message timeout, a separate mechanism). On interruption, a new datastore method PartialCommit narrows the lease’s low bound — UPDATE lease SET low = $lastProcessed — keeping the same token and same until, so the untouched suffix rides the existing crash-recovery reclaim path. The write goes through context.WithTimeout(context.WithoutCancel(ctx), AckMargin), the same “extra time to record outcomes” pattern ShutdownFunc already uses, since the ctx that triggered the interruption is already Done.

Consequences. The resolved prefix is never redelivered; the suffix needs no new expiry machinery; the waterline’s exception-blocker and lease-narrowing terms combine via LEAST. Rejected: freeing the lease outright — redelivers work already done.