Skip to content

feat(sqs): QueueNameExists on attribute conflict, seedable QueueDeletedRecently (#429) - #440

Closed
scttfrdmn wants to merge 1 commit into
fix/431-run-instances-countsfrom
fix/429-sqs-createqueue-errors
Closed

scttfrdmn wants to merge 1 commit into
fix/431-run-instances-countsfrom
fix/429-sqs-createqueue-errors

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #429

The defect

createQueue was unconditionally idempotent — it returned the existing queue's URL regardless of what the request asked for. Two stacks or two test cases claiming one queue name with different settings both "succeeded", and the second silently inherited the first one's configuration. That is a confidently wrong answer rather than a missing error, and the consumer's error branch was unreachable. AWS documents two failures on CreateQueue; neither was modeled.

Stacked on #438 (fix/431-run-instances-counts) — both touch CHANGELOG.md and docs/services.md. Base retargets to main automatically when #438 merges.

QueueNameExists — state-determined, no seed

400 when a name is reused with differing attribute values; same name with the same values stays idempotent.

No seed, because the condition is entirely determined by state: it fires on the real mistake rather than only when a harness remembers to arm it.

Which differences count

Only attributes present in the request are compared. An omitted attribute is "no opinion", not an assertion of its default.

The CreateQueue reference says two things that pull in different directions — that providing "the exact same names and values for all its attributes" returns the existing URL, and that the error fires "only if the request includes attributes whose values differ from those of the existing queue". I took the narrower reading: the first is a sufficient condition for idempotency, not a necessary one, so it does not contradict the error's own definition.

It is also the only reading that keeps substrate's own CFN path working. deploySQSQueue forwards only the properties a template declares, so a stack that dropped a property between deploys would send a strict subset on re-deploy and fail to update at all under the strict reading.

Resolving through defaults

An existing queue's unset attributes resolve through the values getQueueAttributes reports before comparing. A queue created with no attributes has an empty map but observably reports VisibilityTimeout=30, so a request naming VisibilityTimeout=30 asks for exactly what it already has — comparing raw map entries would reject a request AWS accepts.

sqsAttributeDefaults deliberately mirrors getQueueAttributes' inline fallbacks rather than the AWS reference, so the comparison and read paths cannot disagree about a queue's effective attributes. That carries one known staleness through: MaximumMessageSize is 262144 here where AWS documents 1 MiB. Filed as #439 rather than smuggled in, since correcting it changes GetQueueAttributes output.

The FifoQueue trap

Substrate derives FifoQueue from the .fifo name suffix and never copies it into Attributes. A naive map comparison would compare "true" against an absent value and reject the most ordinary FIFO re-create there is — FifoQueue=true, what every SDK and CloudFormation template sends. Resolved from the queue's own flag instead, and pinned by test.

Attributes are checked in sorted order, so the attribute named in the message is deterministic; a message varying by map iteration order would make the error irreproducible.

The message carries AWS's documented wording plus the offending attribute name, which AWS's own text omits — without it the error is nearly undiagnosable for a caller holding a large attribute set.

Seedable QueueDeletedRecently

AWS requires a 60-second wait after DeleteQueue before the same name can be reused. Substrate keeps no memory of a delete, so a consumer's delete → recreate → retry loop had no reachable error branch.

curl -X POST http://localhost:4566/v1/sqs/consistency \
  -d '{"queueName":"run-q","deletedRecentlyMisses":2}'

Rides on the existing /v1/sqs/consistency seed as a third counter: same endpoint, same name-over-wildcard precedence, same DELETE, same state reset. Counted rather than timed for the reason the lookup windows are — the real condition is a wall-clock window, and a wall-clock window would make the assertion depend on how long the rest of the test took.

Unlike the two lookup counters it is not gated on the queue existing, since QueueDeletedRecently is precisely the absent case — gating it on existence would make it unreachable. A create that hits an existing queue is an idempotent success and does not spend the budget. The counter defaults to 0, so an unseeded recreate is still instant.

Both codes verified to dispatch

Applying the #413 lesson rather than assuming:

  • botocore — the SQS model declares both exception shapes and lists them under CreateQueue.errors.
  • aws-sdk-go-v2 service/[email protected] — deserializers.go:619,622 matches both with strings.EqualFold.

Neither has a legacy alias, unlike QueueDoesNotExist.

Blast radius

No existing test creates the same queue twice with attributes. The only re-create path is CFN (UpdateStack → Deploy → deploySQSQueue), which forwards only declared properties — hence the "no opinion" decision. All existing TestSQS/TestCFN tests pass unchanged.

Tests

28 subtests in the new emulator/sqs_createqueue_test.go, covering both wire protocols: the conflict cases, the idempotent cases including explicit-value-equal-to-default and subset, the three FIFO branches, message content, determinism across 20 runs, that a conflict creates nothing, the seeded window, that it does not apply to an existing queue, counter independence, the wildcard, negative rejection, and the state-failure path.

Mutation-tested. Disabling the conflict check, the defaults resolution, and the FifoQueue derivation each fails the tests covering it. The FIFO case initially did not fail: the test passed FifoQueue=true on the first create, so the value landed in Attributes and the derivation branch was never reached. The test is now split so the derived and standard-queue branches are both exercised — a real coverage gap that green tests hid.

Verification

gofmt, go build ./..., go vet ./..., golangci-lint run ./... (0 issues), make test (race), test/e2e, make docs-reference-check docs-versions. All internal docs/services.md anchors verified to resolve.

…edRecently (#429)

CreateQueue was unconditionally idempotent: it returned the existing queue's URL
regardless of what the request asked for, so two stacks or two test cases
claiming one queue name with different settings both "succeeded" and the second
silently inherited the first one's configuration. That is a confidently wrong
answer rather than a missing error, and it left the consumer's error branch
unreachable. AWS documents two failures here, and neither was modeled.

QueueNameExists (400) now fires when a name is reused with differing attribute
values. Only attributes present in the request are compared, per the error's own
definition in the CreateQueue reference — "only if the request includes
attributes whose values differ from those of the existing queue" — so an omitted
attribute is no opinion. That is also the only reading that keeps substrate's own
CFN path working, since deploySQSQueue forwards just the properties a template
declares and a template dropping one would send a strict subset on re-deploy.

An existing queue's unset attributes resolve through the same defaults
getQueueAttributes reports before comparing, so VisibilityTimeout=30 against a
bare queue is not a conflict — comparing raw map entries would reject a request
AWS accepts. FifoQueue is resolved from the queue's own flag, because substrate
derives it from the .fifo suffix and never copies it into Attributes; without
that, re-creating a FIFO queue with FifoQueue=true — what every SDK and template
sends — would be rejected. Attributes are checked in sorted order so the
attribute named in the message is reproducible.

QueueDeletedRecently (400) is seedable via deletedRecentlyMisses on the existing
/v1/sqs/consistency seed: same endpoint, same name-over-wildcard precedence, same
DELETE, same state reset. Counted rather than timed for the reason the lookup
windows are — the real condition is a 60-second wall-clock window, and a
wall-clock window would make the assertion depend on how long the rest of the
test took. Unlike the lookup counters it is not gated on the queue existing,
since QueueDeletedRecently is precisely the absent case; a create that hits an
existing queue is an idempotent success and does not spend the budget. The
counter defaults to 0, so an unseeded recreate is still instant.

Both codes were verified to dispatch before shipping, applying the #413 lesson:
botocore's SQS model declares both exception shapes and lists them under
CreateQueue.errors, and aws-sdk-go-v2/service/sqs deserializers.go matches both
with strings.EqualFold. Neither has a legacy alias, unlike QueueDoesNotExist.

Filed #439 rather than fixing it here: sqsAttributeDefaults mirrors
getQueueAttributes' stale MaximumMessageSize of 262144 where AWS documents
1 MiB. Mirroring keeps the comparison and read paths from disagreeing about a
queue's effective attributes; correcting the value changes GetQueueAttributes
output and belongs in its own change.

Mutation-tested: disabling the conflict check, the defaults resolution, and the
FifoQueue derivation each fails the tests that cover it. The FIFO case initially
did not fail, because the test passed FifoQueue=true on the first create so the
value landed in Attributes and the derivation branch was never reached; the test
is now split so the derived and standard-queue branches are both exercised.

Closes #429
@scttfrdmn

Copy link
Copy Markdown
Owner Author

Superseded by #442. GitHub auto-closed this when its base branch fix/431-run-instances-counts was deleted on #438's squash merge, and a PR whose base branch is gone cannot be reopened or retargeted. The same commit, rebased onto main and re-verified, is now at #442 — where CI actually runs, since every workflow filters pull_request: branches: [main].

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.

1 participant