Skip to main content

Deliveries repeat or leases are lost

Redelivery is expected when a claim is not acknowledged before recovery. The investigation is whether retries follow the application's policy or indicate insufficient processing time, failed renewal, uncertain settlement, or workers continuing after ownership ends.

A repeated business event can also be a second publication rather than a retry of the same delivery. Compare application event IDs as well as PostgreMQ message IDs.

Identify the kind of repetition​

EvidenceInterpretation
Same message ID and queue, another claimRedelivery. The count rises after nack or lease expiry, is unchanged across release followed by reclaim, and restarts from zero on DLQ requeue (the next claim increments it to one).
Different message IDs, same application event IDPossible duplicate publication or deliberate replay through publishing.
Same message ID, different queueIndependent subscribers; expected fan-out.
External effect repeated without another recorded claimInvestigate application retries and ambiguous downstream responses.

Inspect retained state:

SELECT * FROM postgremq.list_messages('jobs');
SELECT * FROM postgremq.queue_metrics() WHERE queue_name = 'jobs';
SELECT * FROM postgremq.list_dlq_messages() WHERE queue_name = 'jobs';

Correlate attempts with worker start, stop, cancellation, and acknowledgement logs. A successful callback return and a committed acknowledgement are not the same event. Check whether automatic settlement failed after the handler finished.

Investigate renewal loss​

Check database availability, pool acquisition latency, lock waits, long transactions, and visibility-timeout settings. Automatic extension requires successful database communication before the confirmed lease ends. A transiently busy renewal does not immediately prove ownership was lost, but unresolved contention can consume the remaining window.

Check clock synchronization on application and database hosts. Avoid using unusually small timeouts to accelerate crash recovery without testing renewal under expected load. Compare processing duration and renewal pressure with the capacity of the connection pool.

If automatic extension was disabled, verify that the application renews manually or reliably finishes within the claim window. Stream consumers still normally receive automatic extension; switching consumer style does not disable it.

Handle settlement errors​

A token-ownership error means the requested settlement is not valid for the current delivery state. Do not retry indefinitely using the old message object. It may have been settled, removed, retired, or claimed by another worker.

At the SQL layer, acknowledgement checks the processing state and token; elapsed time alone does not necessarily reject the call if no replacement claim has occurred. That does not grant application permission to ignore SDK ownership cancellation. Once the SDK says to stop, treat further effects as unsafe and let the documented recovery policy apply.

A transport failure is different: settlement may have committed without its response reaching the application. Investigate durable application state and idempotency records rather than assuming the effect must be performed again.

Recover without amplifying effects​

Fix pool starvation, deadlines, or database availability before adding workers. Ensure handlers respond to cancellation and use bounded downstream calls. Use Idempotent consumers for atomic database effects and external idempotency keys.

Observe renewal-loss metrics, repeat attempts, and completion age after the fix. Do not disable attempt limits merely to hide DLQ growth. Repeatedly failing FIFO heads can block useful work indefinitely; resolve their failure policy explicitly.