-
Notifications
You must be signed in to change notification settings - Fork 51
feat(deliverymq): bound retry task receives with backoff and DLQ #997
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
alexluong
merged 2 commits into
hookdeck:main
from
LendritIbrahimi:lendritibrahimi/feat/retrymq-max-receive-dlq
Jul 22, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| package scheduler | ||
|
|
||
| import ( | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestCalculateExecBackoff(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| base time.Duration | ||
| receiveCount uint64 | ||
| maxBackoff time.Duration | ||
| want time.Duration | ||
| }{ | ||
| { | ||
| name: "first receive uses base", | ||
| base: 30 * time.Second, | ||
| receiveCount: 1, | ||
| maxBackoff: 15 * time.Minute, | ||
| want: 30 * time.Second, | ||
| }, | ||
| { | ||
| name: "backoff doubles per receive", | ||
| base: 30 * time.Second, | ||
| receiveCount: 5, | ||
| maxBackoff: 15 * time.Minute, | ||
| want: 8 * time.Minute, | ||
| }, | ||
| { | ||
| name: "backoff is capped", | ||
| base: 30 * time.Second, | ||
| receiveCount: 6, | ||
| maxBackoff: 15 * time.Minute, | ||
| want: 15 * time.Minute, | ||
| }, | ||
| { | ||
| name: "base above cap is capped on first receive", | ||
| base: 30 * time.Minute, | ||
| receiveCount: 1, | ||
| maxBackoff: 15 * time.Minute, | ||
| want: 15 * time.Minute, | ||
| }, | ||
| { | ||
| name: "large receive count does not overflow", | ||
| base: 30 * time.Second, | ||
| receiveCount: ^uint64(0), | ||
| maxBackoff: 15 * time.Minute, | ||
| want: 15 * time.Minute, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| require.Equal(t, tt.want, calculateExecBackoff(tt.base, tt.receiveCount, tt.maxBackoff)) | ||
| }) | ||
| } | ||
| } |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One edge case to handle before merge: the receive count can survive a
Scheduleoverwrite, which makes this check fire early for a freshly scheduled task.Rclives in the<id>:rchash field, incremented by the receive script and cleared only byDeleteMessage. ButSendMessagewith a custom ID — which is exactly whatScheduledoes with the deterministic retry ID (eventID:destinationID) to guarantee at most one pending retry per event+destination — overwrites the message body and score while leaving<id>:rcuntouched.So this sequence inherits a stale count:
maxReceiveCountreal receives. (Same thing if exec succeeded butDeleteMessagefailed, leaving rc behind.)The consequence is bounded (early DLQ, never a loop or loss), but the count should mean "receives of this task," not accumulated history of the ID slot.
Suggested fix: in
SendMessage(rsmq.go), when a custom ID is provided, clear the counters in the existing tx so the reset is atomic with the overwrite — mirroring whatDeleteMessagealready deletes:A test that schedules over a message with rc > 0 and asserts the full
maxReceiveCountbudget is available again would lock it in.