SQLStreams

the messaging platform that is just Postgres

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

0292 — AbandonedRoutines.Remove runs after recover() within the same defer

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

Context. The spawned goroutine’s single defer both recovers panics and removes the goroutine’s registry entry. Ordering matters: if Remove ran first and itself panicked (for example on a nil Metrics), recover() would never run, undoing the panic-recovery guarantee entirely.

Decision. recover() executes first, then AbandonedRoutines.Remove, inside the same defer.

Consequences. A registry failure can never mask a consumerFunc panic. Rejected: a nil-guard on Metrics inside callSafely, and a second nested defer/recover around just the Remove call — validate() already guarantees Metrics != nil before a WorkConsumer can be used, and the convention is to trust that guarantee once, at construction, rather than re-checking it at every downstream call site.