fix(sqs): scope FIFO dedup per MessageGroupId when DeduplicationScope=messageGroup (#908)

* fix(sqs): scope FIFO dedup per MessageGroupId when DeduplicationScope=messageGroup

FIFO queues default to queue-wide deduplication, but the high-throughput
configuration (DeduplicationScope=messageGroup,
FifoThroughputLimit=perMessageGroupId) scopes dedup to each
MessageGroupId. Floci was always keying the dedup cache by
MessageDeduplicationId alone, so two SendMessage calls that shared a
dedupId across different message groups would have the second silently
swallowed even when the queue's DeduplicationScope said they were
distinct.

When DeduplicationScope=messageGroup, key the dedup cache by
(messageGroupId, dedupId) and constrain the duplicate-lookup helper
to the same group. Queue-scoped behavior is unchanged (still keyed
on dedupId alone, lookup spans all groups), and a regression test
covers both paths.

* fix(sqs): use NUL delimiter for group-scoped FIFO dedup key

'|' is in the allowed character set for both MessageGroupId and
MessageDeduplicationId, so the composite key collides — e.g.
(group="a", dedup="b|c") and (group="a|b", dedup="c") both produce
"a|b|c". Use NUL (which is not allowed in either field) so the
composite key is unambiguous, and add a regression test.
This commit is contained in:
Stuart Lang authored and GitHub committed 2026-05-18 20:53:33 -05:00
1 parent 92c5c26763
commit 337b35c938
3 files changed
+58 -4

No files matched your search

@@ -596,6 +596,44 @@ class SqsServiceTest {
assertEquals("msg3", third.get(0).getBody());
}
@Test
void fifoDedup_scopedToMessageGroup_acceptsSameDedupIdAcrossGroups() {
Queue fifo = sqsService.createQueue("fair.fifo",
Map.of("FifoQueue", "true",
"DeduplicationScope", "messageGroup",
"FifoThroughputLimit", "perMessageGroupId"));
sqsService.sendMessage(fifo.getQueueUrl(), "A", 0, "groupA", "sameDedup");
sqsService.sendMessage(fifo.getQueueUrl(), "B", 0, "groupB", "sameDedup");
List<Message> received = sqsService.receiveMessage(fifo.getQueueUrl(), 10, 30, 0);
assertEquals(2, received.size());
}
@Test
void fifoDedup_scopedToMessageGroup_dedupKeyHasNoCollisionFromDelimiterInIds() {
// AWS allows '|' (and other punctuation) in both MessageGroupId and
// MessageDeduplicationId, so a naive "group|dedup" cache key could collide:
// (group="a", dedup="b|c") and (group="a|b", dedup="c") both yield "a|b|c".
// Both pairs must be treated as distinct messages.
Queue fifo = sqsService.createQueue("collision.fifo",
Map.of("FifoQueue", "true",
"DeduplicationScope", "messageGroup",
"FifoThroughputLimit", "perMessageGroupId"));
sqsService.sendMessage(fifo.getQueueUrl(), "A", 0, "a", "b|c");
sqsService.sendMessage(fifo.getQueueUrl(), "B", 0, "a|b", "c");
List<Message> received = sqsService.receiveMessage(fifo.getQueueUrl(), 10, 30, 0);
assertEquals(2, received.size());
}
@Test
void fifoDedup_queueScope_rejectsSameDedupIdAcrossGroups() {
Queue fifo = sqsService.createQueue("queue-scoped.fifo",
Map.of("FifoQueue", "true"));
sqsService.sendMessage(fifo.getQueueUrl(), "A", 0, "groupA", "sameDedup");
sqsService.sendMessage(fifo.getQueueUrl(), "B", 0, "groupB", "sameDedup");
List<Message> received = sqsService.receiveMessage(fifo.getQueueUrl(), 10, 30, 0);
assertEquals(1, received.size());
}
@Test
void purgeQueueWithClearFifoDelegatesToSnsForFifoDedupOnSubscribedTopics() {
final var sns = mock(SnsService.class);