Skip to content

tagging: the four merge helpers store a resource's tags in Go map order, so one state hashes two ways #862

Closed

Description

@scttfrdmn

Surfaced while auditing the tagging writer for #845 and fixed in the same PR (#851). Filed for the record: it is the kind of nondeterminism an event-sourced emulator cannot carry, and it was invisible because nothing compared state it had not changed.

What substrate did

All four slice-returning merge helpers in mergeResourceTags — EC2, IAM, ECS and EFS — built their result by ranging over a Go map. Map iteration order is randomised per run, so two identical runs stored one resource's tags in different orders.

Three consequences:

  1. ListTagsForResource, DescribeTags and GetResources reported a different order each run for the same state. Nothing in substrate asserted on order, which is why no test caught it.
  2. A hash over the stored record differed when nothing about the record had changed.
  3. (2) is the one that matters here. Substrate's whole proposition is that the same inputs give the same outputs and that a failing run replays exactly — which requires being able to compare state a replay did not change and find it equal. A record whose byte content depends on map iteration order breaks that for every resource that carries a tag. Replay bypasses authorization, quota, consistency and fault injection #833's ValidateState work, in this same release, is what would have started reporting it as a spurious difference on every event.

What shipped in #851

All four helpers sort by key, which is the answer DescribeStacks already gives for a stack's own tags.

Closed as shipped. See #851 and the ## [Unreleased] entry in CHANGELOG.md. The remaining ordering nondeterminism of the same shape is not fixed and is much larger: MemoryStateManager.List returns Go map order with no sort, across 118 state.List( call sites in 41 files of which only 11 contain any sort. call — so two identical ListBuckets requests in one run can differ. That belongs with #817, whose analysis records it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions