Repository navigation
feat(consumer): count unfinished deliveries and release claims by owner - #9
Merged
Merged
Conversation
A handler that kills its process (OOM, exit, SIGKILL) never reports a failure, so its message came back with the same attempts for ever. The transports now count a delivery that never ended in an ack, release or dead-letter when they hand the message out again, and the worker dead-letters it at maxAttempts. - PDO: taking over a lapsed reservation raises attempts (column and envelope) in the same UPDATE, so one worker counts it; no schema change. - Redis: reserve() records deliveries in a <queue>:started sorted set that ack/release/deadLetter clear; a body that returns with its entry still there is counted in the body and the processing entry. Body format is unchanged. - AMQP: the broker's redelivered flag counts one attempt. - Waiting on an in-flight key is a release and is never counted. Add the optional OwnershipAwareIdempotencyStore (claimOwned/forgetOwned) so a handler that outlived its lease cannot delete the claim or the completed record of the worker that took over. Stores without it keep claim() and forget().
An abandoned message that reached maxAttempts was dead-lettered before the idempotency store was read, so a message whose handler had finished (only the ack was lost) landed in the failed table, and one whose key another handler still held was failed instead of waiting. The dispatcher now drops it as a duplicate when the key is recorded and releases it as in_flight when the key is still claimed; only a message with neither is dead-lettered. RedisTransport counting no longer fails a reservation: a NOPERM or unknown command refusal of ZREMRANGEBYSCORE or LINSERT switches the counting off, and any other failure while counting hands the message out uncounted instead of leaving it on the processing list.
…a claim An exhausted message whose key was still claimed was released as in_flight, which clears the transport's unfinished-delivery marker. When it came back it was no longer abandoned, so the handler ran again; with a lease longer than the transport's redelivery time a handler that kills its process every time never reached the dead-letter queue. The worker now treats any message that arrives with attempts at or above maxAttempts and no dead_letter block as exhausted, since only the count can bring a live message there. A replayed dead letter keeps its block and runs as before. A store that cannot tell a recorded key from a claimed one now dead-letters an exhausted message instead of discarding it.
muhammetsafak
deleted the
feat/queue-ownership-and-abandoned-attempts
branch
November 28, 2026 09:30
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
exitorSIGKILLnever reports a failure, so its message came back with the sameattemptsfor ever. Transports now count a delivery that never ended in an ack, release or dead-letter when they hand the message out again; theWorkerdead-letters it (reasonfailed) onceattemptsreachesmaxAttempts, without running the handler again.attempts(column and envelope) in the sameUPDATE. No schema change.reserve()records deliveries in a<queue>:startedsorted set (SHA-1 of the body) thatack/release/deadLetterclear. A body that returns with its entry still there is counted, in the body and the processing entry. Body format unchanged; a client without the sorted-set commands switches counting off.redeliveredflag counts one attempt. A classic queue keeps no delivery count, so repeated crashes are not bounded there (documented).OwnershipAwareIdempotencyStore(claimOwned()/forgetOwned()), used by theDispatcherwhen the store implements it, so a handler that outlived its lease cannot delete the claim or completed record of the worker that took over.IdempotencyStore::forget()is unchanged; stores without the interface behave as before.InMemoryIdempotencyStoreimplements it.Backward compatible (Queue 2.4.0 candidate): no signature of
IdempotencyStore,ConsumerTransportorHandlerchanged, no body format change.ReceivedMessageandRedisTransportgain a new optional last constructor argument.Tests
jobs_failed(PDO) /:failed(Redis, in-memory and real-Redis integration); AMQP redelivered flag; MySQL and RabbitMQ integration cases added.forget()works unchanged.in_flightwaiting repeated pastmaxAttemptsconsumes no attempt and never dead-letters.Docs: Retries & Dead-Letters, Idempotent Consumption (claim ownership, upgrading from 2.3), Transport PDO/Redis/RabbitMQ, API Reference, README, CHANGELOG.