Repository navigation
feat(sqs): enforce MaximumMessageSize on SendMessage (#454) - #462
Merged
Merged
Conversation
SendMessage and SendMessageBatch accepted a body of any length, so a consumer's oversized-payload branch was unreachable: the call returned a MessageId, the message was enqueued, and a suite testing the failure path reported green while verifying nothing. Both operations now measure the message and reject it before anything observable happens. The limit is the queue's effective MaximumMessageSize, read through the same getAttrOrDefault call the read path uses, so the number GetQueueAttributes reports and the number enforced cannot diverge. A malformed attribute value falls back to the default rather than to zero, which would reject every message including an empty one. Message attributes count toward the measured size — AWS states that "all components of a message attribute are included in the 1 MiB message size restriction" — so the name, data type and value are each measured as UTF-8 bytes, with a binary value counted at its raw length rather than its base64 length. Message *system* attributes are excluded, per the same page. SendMessageBatch enforces two limits: each entry against the queue's per-message cap, and the combined payload against the request cap. The total is checked first, which is not arbitrary ordering — the two limits are equal on a default queue, so a batch carrying one oversized entry breaches the total too, and real AWS reports BatchRequestTooLong for that case rather than the per-message error. Neither limit lowers the other: a queue with a 1 KiB MaximumMessageSize still accepts a batch of ten 1 KiB entries. Nothing is enqueued when a batch is rejected, so a retry does not re-send entries that already landed. On a FIFO queue the size check runs ahead of the deduplication branch. A rejected send that had already recorded a deduplication ID would poison the dedup window for the corrected retry, silently swallowing it — a worse failure than the one being fixed, because it looks like success. Provenance, stated plainly: the SendMessage reference declares no oversized-message error at all, and its InvalidMessageContents is documented as a character-set error, so neither the code nor the wording is derivable from the API model. InvalidParameterValue with HTTP 400 and both message strings come from observed real-AWS responses captured in consumer bug reports (artilleryio/artillery#3463 for the per-message case, aws/aws-sdk-go-v2#3026 for the batch case); independent reimplementations emit the same text, which corroborates it as transcribed AWS wording rather than one project's invention. Message attributes are parsed for measurement only; storing and returning them on ReceiveMessage is tracked separately in #461.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
9 tasks
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.
Closes #454
SendMessageandSendMessageBatchaccepted a body of any length. The callreturned a
MessageId, the message was enqueued, and a consumer'soversized-payload branch was unreachable — a suite testing that failure path
reported green while verifying nothing. #439 corrected the reported
MaximumMessageSizedefault to 1 MiB but deliberately left enforcement out ofscope; this closes it.
What the reference actually says — and doesn't
The issue's first acceptance criterion was "confirm the exact error code and
message against the current SendMessage API reference — do not assume." Taken
literally, that turned up the finding worth leading with: the reference
declares no oversized-message error at all.
SendMessage's error list has noentry for it, its
InvalidMessageContentsis documented as a character-seterror (not a length one), and
BatchRequestTooLongis declared only onSendMessageBatch.So neither the code nor the wording is derivable from the API model. Provenance,
stated plainly rather than implied:
InvalidParameterValueOne or more parameters are invalid. Reason: Message must be shorter than N bytes.BatchRequestTooLongBatch requests cannot be longer than N bytes. You have sent M bytes.Both come from real-AWS responses captured in consumer bug reports
(artilleryio/artillery#3463; aws/aws-sdk-go-v2#3026). Independent
reimplementations emit the same strings, which corroborates them as transcribed
AWS text rather than one project's invention. That is weaker than a doc citation
and the code comment, CHANGELOG and
docs/services.mdall say so.Semantics
MaximumMessageSize, resolved throughsqsDefaultMaximumMessageSizevia the samegetAttrOrDefaultcall the readpath uses, so the number
GetQueueAttributesreports and the number enforcedcannot diverge. A malformed value falls back to the default, not to zero —
zero would reject every message including an empty one.
limit+1 is rejected.
included in the 1 MiB message size restriction." Name + data type + value,
each as UTF-8 bytes, with a binary value measured at its raw length rather
than its base64 length. Message system attributes are excluded, per the same
page. The issue listed this as an open question.
queue's per-message cap; the combined payload against the request cap. The
total is checked first — not arbitrary: the two limits are equal on a
default queue, so a batch carrying one oversized entry breaches the total too,
and real AWS reports
BatchRequestTooLongfor that case rather than theper-message error. Neither limit lowers the other: a queue with a 1 KiB
MaximumMessageSizestill accepts ten 1 KiB entries in one batch.before storing any, so a retry does not re-send entries that already landed.
The query path walks the entries twice for exactly this reason.
deduplication ID would poison the dedup window for the corrected retry,
silently swallowing it — a worse failure than the one being fixed, because it
looks like success.
Tests
New
emulator/sqs_messagesize_test.go(~490 lines), both wire protocols wherethe behaviour differs by protocol. Notable cases: exactly-at-limit vs +1;
enforcement reading the queue attribute rather than a constant (a
constant-based check passes every other test in the file and fails this one);
the error naming the queue's limit and not the default; attributes accumulating
to breach; a binary value straddling the limit only when measured base64
(asserting both bounds); FIFO retry after rejection succeeding with the same
dedup ID; a 1 KiB queue still accepting a legal ten-entry batch; malformed
attribute values falling back.
Mutation testing: 13/13 caught. The ones that justified their existence —
batch total compared against the per-message limit; the two batch checks
reordered (which decides whether AWS's actual error code is reported); a binary
value measured base64-encoded; and the error message hardcoding the default
limit.
Verification
All from the repo root:
gofmt -lclean;go build/go vetOK;golangci-lint run ./...0 issues;make test(race,-count=1) passing;make docs-reference-check docs-versionspassing;test/e2epassing. New fileat 93.8–100% per function.
Deliberately out of scope
Message attributes are parsed for measurement only — substrate does not yet
store or return them on
ReceiveMessage. Filed as #461 so the code comment'sreference points at something real.