Fix duplicate DeleteMessageBatchRequestEntry ids when SQS redelivers a message within one ack batch#1654
Open
BK202503 wants to merge 1 commit into
Open
Conversation
…a message within one ack batch Standard SQS queues can redeliver the same message before the acknowledgement batch is flushed. SqsAcknowledgementExecutor was using MessageHeaderUtils.getId (the Spring message id derived from the SQS messageId) as the batch entry id, so a duplicate delivery within the same batch produced two entries with the same DeleteMessageBatchRequestEntry.id — AWS then rejected the whole batch with BatchEntryIdsNotDistinctException. Switch to a positional-index id. The batch entry id is only a request-local correlation token, so a per-request unique value is sufficient. Partial-failure correlation now maps failed ids back to messages by index; if AWS returns an id that isn't a valid index the executor still falls back to the "cannot correlate all failure ids" path. Fixes awspring#1634 Signed-off-by: BK202503 <199436087+BK202503@users.noreply.github.com>
BK202503
requested review from
MatejNedic,
maciejwalkowiak and
tomazfernandes
as code owners
July 21, 2026 16:38
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.
Summary
SqsAcknowledgementExecutorusedMessageHeaderUtils.getId(message)— the Spring message id derived from the SQSmessageId— as theDeleteMessageBatchRequestEntry.id. On a Standard queue, if the same SQS message is redelivered within one acknowledgement batch, two entries end up with the same id and AWS rejects the entire batch withBatchEntryIdsNotDistinctException. The reporter's analysis and full repro are in #1634.Fix
Batch entry id is now a positional index into the snapshot list of messages passed to
deleteMessageBatch. SQS only requires the id to be unique within a single request and doesn't otherwise interpret it, so a positional index is sufficient and keeps the mapping trivial.Partial-failure correlation is updated accordingly:
createPartialFailureExceptionparses eachBatchResultErrorEntry.idas an index into the ordered batch and buckets messages by index. If any returned id doesn't parse to a valid index — which shouldn't happen but preserves the previous defensive behaviour — the executor still returns the existing "cannot correlate all failure ids" case, treating every message as failed.Tests
shouldUseUniqueBatchEntryIdsWhenMessageIdIsDuplicated— two mock messages sharing the same Spring message id (viaMessagingMessageHeaderswith an explicit shared UUID) but with distinct receipt handles → asserts the capturedDeleteMessageBatchRequestentries have distinct ids and preserve both receipt handles in order. Fails onmain(BatchEntryIdsNotDistinctExceptionpath exercised), passes with this change.shouldWrapPartialBatchFailurenow usesid("0")(positional) instead of the message-header UUID../mvnw -pl spring-cloud-aws-sqs -am test— includes localstack integration tests).Fixes #1634