Skip to content

feat(sqs): enforce MaximumMessageSize on SendMessage (#454) - #462

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/454-sqs-message-size
Aug 1, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/454-sqs-message-size

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #454

SendMessage and SendMessageBatch accepted a body of any length. The call
returned a MessageId, the message was enqueued, and a consumer's
oversized-payload branch was unreachable — a suite testing that failure path
reported green while verifying nothing. #439 corrected the reported
MaximumMessageSize default to 1 MiB but deliberately left enforcement out of
scope; 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 no
entry for it, its InvalidMessageContents is documented as a character-set
error (not a length one), and BatchRequestTooLong is declared only on
SendMessageBatch.

So neither the code nor the wording is derivable from the API model. Provenance,
stated plainly rather than implied:

Code HTTP Wire message
Per-message InvalidParameterValue 400 One or more parameters are invalid. Reason: Message must be shorter than N bytes.
Batch total BatchRequestTooLong 400 Batch 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.md all say so.

Semantics

  • Effective limit — the queue's MaximumMessageSize, resolved through
    sqsDefaultMaximumMessageSize via the same getAttrOrDefault call the read
    path uses, so the number GetQueueAttributes reports and the number enforced
    cannot diverge. A malformed value falls back to the default, not to zero —
    zero would reject every message including an empty one.
  • Boundary is inclusive — a message of exactly the limit is accepted;
    limit+1 is rejected.
  • Attributes count. AWS: "all components of a message attribute are
    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.
  • Two batch limits, and the order matters. Each entry is checked against the
    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 BatchRequestTooLong for that case rather than the
    per-message error. Neither limit lowers the other: a queue with a 1 KiB
    MaximumMessageSize still accepts ten 1 KiB entries in one batch.
  • Nothing is enqueued on rejection. Both protocol paths size every entry
    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.
  • FIFO: size before dedup. 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.

Tests

New emulator/sqs_messagesize_test.go (~490 lines), both wire protocols where
the 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 -l clean; go build/go vet OK;
golangci-lint run ./... 0 issues; make test (race, -count=1) passing;
make docs-reference-check docs-versions passing; test/e2e passing. New file
at 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's
reference points at something real.

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

codecov Bot commented Aug 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.45455% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/sqs_messagesize.go 92.98% 2 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 84a7ee8 into main Aug 1, 2026
16 checks passed
@scttfrdmn
scttfrdmn deleted the feat/454-sqs-message-size branch August 2, 2026 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SQS: SendMessage does not enforce MaximumMessageSize

1 participant