Skip to content

Fix duplicate DeleteMessageBatchRequestEntry ids when SQS redelivers a message within one ack batch - #1654

Merged
tomazfernandes merged 1 commit into
awspring:mainfrom
BK202503:fix/sqs-ack-duplicate-batch-entry-id
Jul 25, 2026
Merged

Fix duplicate DeleteMessageBatchRequestEntry ids when SQS redelivers a message within one ack batch#1654
tomazfernandes merged 1 commit into
awspring:mainfrom
BK202503:fix/sqs-ack-duplicate-batch-entry-id

Conversation

@BK202503

Copy link
Copy Markdown
Contributor

Summary

SqsAcknowledgementExecutor used MessageHeaderUtils.getId(message) — the Spring message id derived from the SQS messageId — as the DeleteMessageBatchRequestEntry.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 with BatchEntryIdsNotDistinctException. 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: createPartialFailureException parses each BatchResultErrorEntry.id as 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

  • New regression test: shouldUseUniqueBatchEntryIdsWhenMessageIdIsDuplicated — two mock messages sharing the same Spring message id (via MessagingMessageHeaders with an explicit shared UUID) but with distinct receipt handles → asserts the captured DeleteMessageBatchRequest entries have distinct ids and preserve both receipt handles in order. Fails on main (BatchEntryIdsNotDistinctException path exercised), passes with this change.
  • Existing partial-failure test updated: shouldWrapPartialBatchFailure now uses id("0") (positional) instead of the message-header UUID.
  • Full sqs module test suite: 634 tests, 0 failures, 0 errors, 5 skipped (./mvnw -pl spring-cloud-aws-sqs -am test — includes localstack integration tests).

Fixes #1634

…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>
@github-actions github-actions Bot added the component: sqs SQS integration related issue label Jul 21, 2026

@tomazfernandes tomazfernandes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @BK202503, looking forward to more.

@tomazfernandes
tomazfernandes merged commit a123519 into awspring:main Jul 25, 2026
6 checks passed
BK202503 added a commit to BK202503/BK202503.github.io that referenced this pull request Jul 26, 2026
…72)

awspring/spring-cloud-aws#1654 (Fixes #1634) merged 2026-07-25. 새 topic 페이지 contributions/spring-cloud-aws-1654.html 추가, index에 별도 카드 (SQS ack batch dedup), sitemap 반영.

Co-authored-by: BK202503 <199436087+BK202503@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: sqs SQS integration related issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SQS batched acknowledgement can fail when a standard queue redelivers the same message in one ack batch

2 participants