Repository navigation
Conversation
… API
Adds dead-letter redrive to the queue adapter contract and an admin
endpoint that replays a queue's dead letters onto it, paced so its
workers are not swamped.
- Adapter contract: optional `redrive(deadLetter, target, { limit })`,
surfaced as `queue.redrive(queue, { limit })` on every manager shape.
pg-boss uses its native redrive (one transaction per call), SQS copies
then deletes (at-least-once, FIFO dedup by dead-letter id), memory is
the reference. Held to the conformance suite.
- Storage: a ReplayDeadLetters job chain that moves at most batchSize per
round, stops at the limit, an empty dead-letter queue or maxMinutes,
and moves nothing while the queue has maxBacklog messages waiting or
running.
- Admin: GET /queue/dead-letters, POST /queue/dead-letters/replay.
Coverage Report for CI Build 46415379681Warning Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes. Coverage increased (+0.1%) to 88.798%Details
Uncovered Changes
Coverage Regressions96 previously-covered lines in 7 files lost coverage.
Coverage Stats💛 - Coveralls |
…ckpressure - SQS: a message now carries its idempotency key in the `queue.idempotency-key` attribute, which dead-letter copies keep. A redrive copy joins the original's FIFO group and deduplicates per dead letter, so it is held behind a live message of the same identity and a replay soon after the original send is not dropped as its duplicate. - Replay: parked retries no longer count toward maxBacklog on SQS, where in-flight cannot tell them from running deliveries; the backlog read is capped at maxBacklog (now at most 100,000); a round past its deadline moves nothing. - Integration coverage: manager redrive on pg-boss and SQS, the replay chain end to end on pg-boss, FIFO identity through a dead letter.
This comment has been minimized.
This comment has been minimized.
The five dead letters are sent in one insert, so they are equally old and pg-boss redrives them in no particular order. OrioleDB returned a different three than Postgres. Assert the count per replay and that every dead letter comes back exactly once.
object-admin-delete and object-admin-delete-batch fail mostly when S3 throttles (SlowDown). Under the default policy their first six retries landed within about a minute, right back onto the throttled prefix, and every message of a failed DeleteObjects batch came back at the same moment. - RetryPolicy gains an opt-in `jitter`: each delay is spread at random between half and all of the capped curve. The manager's delay is what both engines apply (pg-boss's own jittered start_after is overwritten on a handler failure), so this spreads retries on pg-boss and SQS. - The two delete queues use a new cleanupRetry: 30s doubling to 6h, jittered, on the same 21 attempts as the default so an SQS queue's maxReceiveCount set in verify provisioning stays valid. The first six retries now take 15 to 30 minutes; a message is dead-lettered after about 2 days on average (1.4 to 2.9).
This branch has not been deployed
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
An admin endpoint to replay a queue's dead letters back onto it, paced so its workers are not swamped. The move itself is part of the generic queue adapter contract, so it works the same on pg-boss and SQS.
Endpoints
GET /queue/dead-letters: every queue with a dead-letter queue of its own, with how many dead letters it holds (fullest first) and how busy the queue it would be replayed onto is right now (outstanding, whatmaxBacklogis measured against). Counts are the engine's sampled gauges, approximate on SQS.POST /queue/dead-letters/replay:queuelimitbatchSizedelaySecondsmaxBacklogmaxMinutesHow it avoids storming workers
The replay runs in the background as a chain of
ReplayDeadLettersjobs, one round per job (the same shape as the v10 to SQS move). Each round moves at mostmin(batchSize, what is left of limit, room under maxBacklog), so the queue never gets more thanmaxBacklogpiled onto it, whatever the pace or however many replays run at once. A round with no room moves nothing and the next one waits at least 15s. The chain ends at the limit, on an empty dead-letter queue, or atmaxMinutes.Replayed messages arrive as fresh messages (attempt 1, same payload, headers and key), so they get their whole retry budget again. One that fails again works through that budget and lands back in the dead-letter queue.
How
Adapter contract (
src/internal/queue/manager)ProducerAdapter.redrive?(deadLetter, target, { limit, queues, signal })returns{ moved, remaining }. Optional, likestats.queue.redrive(queue, { limit }). It resolves the queue's declaredretry.deadLetterand rejects a dead-letter queue shared by several queues (not every engine records which queue a message came from). The sync queue and adapters without the capability reject withNotSupportedError('redrive').Adapters
redrive(). One transaction per call, so nothing is lost or duplicated. It keeps the singleton key and trace context. A job the target's policy refuses (anexclusivequeue that already holds that key) is failed in place in the dead-letter queue, with the reason as its output.previewRedrive()with limit 1 answersremaining.send(batching, size checks, service-fault retries), delete only the dead letters whose copy was confirmed. At-least-once: a crash between copy and delete re-copies. A FIFO target drops that copy within five minutes, because the copy's deduplication id is derived from the dead letter's id. Works for dead letters the adapter copied and ones SQS's redrive policy moved.Storage (
src/storage/events/dead-letters/replay-dead-letters.ts)ReplayDeadLettersevent and handler on a newreplay-dead-lettersqueue (system retry posture, with its own dead-letter queue).replayRound/nextReplayRoundDelay/outstandingOfhold the pacing logic. Outstanding is backlog plus in-flight plus retries due now. Retries parked for later are left out, so a queue with a long-backoff retry pile is not throttled forever.Object delete cleanup retries (
object-admin-delete,object-admin-delete-batch)SlowDown). Under the default policy their first six retries landed within about a minute, back onto the throttled prefix, and every message of a failedDeleteObjectsbatch came back at the same moment.RetryPolicygains an opt-injitter: each delay is spread at random between half and all of the capped curve. The manager's delay is what both engines apply (it overwrites pg-boss's ownstart_afteron a handler failure), so this works on pg-boss and SQS alike. Other queues are unchanged.cleanupRetry: 30s doubling to 6h, jittered, on the same 21 attempts as the default, so an SQS queue'smaxReceiveCountset inverifyprovisioning needs no change. The first six retries now take 15 to 30 minutes; a message is dead-lettered after about 2 days on average (1.4 to 2.9). pg-boss rewrites the queue's policy at startup; jobs already queued keep the schedule they were inserted with.Limits
limitis a ceiling in the normal path, but two failure paths can go past it:Both chains still honour
maxBacklog. A strict cap needs the replay's progress stored durably (which would also give a stop endpoint and a status view); left for a follow-up.There is no stop endpoint:
maxMinutesbounds a replay.No per-tenant filter: SQS cannot filter a queue without receiving from it.
Deploy note
Two new queues:
replay-dead-lettersandreplay-dead-letters-dead-letter. pg-boss provisions them at startup. On SQS withverifyprovisioning they must be created in the infrastructure repo before this ships, or startup fails on the missing queues.Tests
adapters/conformance.ts), three new tests run on every adapter: a dead letter comes back fresh with payload, headers and key intact;limitbounds a call andremainingreports what is left; a dead letter a consumer holds is skipped until it is handed back. Passing on memory, pg-boss (real Postgres) and SQS standard and FIFO (ElasticMQ).sqs-adapter.test.ts: on a partial send, only the dead letters whose copy was confirmed are deleted; copies carry a per-dead-letter idempotency key.manager/redrive.test.ts: end to end on the memory adapter (fail, dead-letter, redrive, handled again at attempt 1), producer-only manager, argument forwarding, request validation, shared or missing dead-letter queue,NotSupportedErroron adapters without the capability and on the sync queue.replay-dead-letters.test.ts: round sizing under batch, limit and backlog room; throttling; no backpressure without stats; delays and every stop condition; the handler chaining the next round.admin/queue.test.ts: scheduling with explicit and default pacing, validation, the listing, and the queue-disabled case.manager/policy.test.ts: jittered delays stay between half and all of the capped curve, including at the cap; a non-booleanjitteris refused at start.storage/events/workers.test.ts: both delete queues keep the default attempt budget and never wait under 15s or over the SQS visibility limit.tscand Biome are clean. The full unit suite passes (4,540 tests), and so doessrc/test/queueagainst throwaway Postgres and ElasticMQ containers.