Skip to content

fix(sqs): the wildcard consistency seed cannot be double-consumed (#582) - #589

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/582-sqs-seed-mutex
Aug 6, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/582-sqs-seed-mutex

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Consuming a seeded consistency miss is a read-modify-write and StateManager has no
compare-and-swap, so the decrement was serialized under a mutex striped by queue
name
. The "*" wildcard seed is shared by every queue but the lock was not: two
concurrent lookups on different names took different stripes, both read the same
budget, both decremented it and both Put. One seeded miss consumed twice.

The issue notes this would flake rather than fail reliably. It does not — with enough
concurrency it fails every time. A wildcard seed of 16 driven by 32 concurrent
GetQueueUrl calls on distinct queues reported 27 misses, then 32 on the next
run: a harness seeding "the next N lookups in this suite miss" saw more than N, and
inconsistently.

The fix, and where it deviates from the issue

The issue proposes adding seedMu alongside queueMu and specifies a
stripe → seed-mutex lock order. Measured before writing any code: queueMu.lock had
exactly one call site — consumeQueueMiss itself.
Nothing else used the stripe set,
so it is replaced rather than supplemented. That removes the lock-order rule along
with the hazard it guarded, which is strictly better than documenting an ordering
between two locks when one suffices. Seed consumption is a harness-frequency
operation, so striping buys nothing here.

The result is the shape S3Plugin.consumeConditionalConflict already has — the seed
this was found next to, in #540 — and the comment cross-references it so the two read
as one decision rather than two coincidences.

Acceptance criteria

  • Concurrent consumption of a wildcard seed from different queue names consumes
    each seeded miss exactly once.
  • A test drives N concurrent lookups against a wildcard seed of M and asserts
    exactly M report the deviation, under -race, failing before the fix —
    measured at 27 and 32 against a seeded 16.
  • The name-scoped path keeps its behaviour, including fall-through to a funded
    wildcard when a name-scoped seed is exhausted (sqs_consistency_test.go's
    existing cases pass unchanged).
  • The "airtight" doc comment is updated — it moves to consumeQueueMiss along
    with the reasoning, since the type it was attached to is gone. It now records
    that the guarantee was airtight for the name-scoped path and not for the
    wildcard one, keeping the two paragraphs that are still true: StateManager has
    no compare-and-swap, and the guarantee is process-local.
  • CHANGELOG.md under ### Fixed.

Tests

TestSQS_Consistency_ConcurrentWildcardAcrossQueues: 32 queues sharing one wildcard
seed of 16, released from a single start channel to maximize overlap. More queues
than budget on purpose — the overspend is only observable as a count if there are
lookups left over to be refused. It also asserts the budget really is spent
afterwards, so a count that comes out right because misses were lost rather than
double-spent still fails.

The pre-existing single-name concurrency test keeps its assertion and gains a comment
saying which case it does not cover, so the two are not mistaken for duplicates.

Mutation testing

Three mutants, anchor-count asserted, gofmt+vet gated, -race, -count=3:

Mutant Verdict
Restore the pre-#582 striped queueMu CAUGHT — 27 then 32 misses against 16
Move the lock to after the Get (the plan's mutant) CAUGHT — both concurrency tests
Remove the lock entirely CAUGHT — both concurrency tests

Verification

Full gate green: gofmt, go build, go vet, golangci-lint (0 issues),
make test (race), make docs-reference-check docs-versions, docs site build,
test/e2e vet + test.

Live against substrate server --address :4673 with the real AWS CLI
(AWS_MAX_ATTEMPTS=1): 16 concurrent get-queue-url calls on 16 distinct queues
against a wildcard seed of 8 → 8 misses, 8 successes, three runs in a row, and
wq-0 resolving normally once the budget is spent.

Closes #582

@scttfrdmn
scttfrdmn merged commit b7a839b into main Aug 6, 2026
@scttfrdmn scttfrdmn mentioned this pull request Aug 6, 2026
@scttfrdmn
scttfrdmn deleted the fix/582-sqs-seed-mutex branch August 9, 2026 17:48
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: a wildcard consistency seed can be double-consumed, because the lock is striped by queue name

1 participant