Skip to content

fix(rds,elasticache): the Marker names the last record of its page (#887) - #914

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/query-marker-cursor-basis
Sep 16, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/query-marker-cursor-basis

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #887.

What was wrong

Three operations — RDS DescribeDBInstances and DescribeDBClusters, ElastiCache DescribeCacheClusters — implemented Marker as a decimal offset into the sorted listing:

marker := req.Params["Marker"]
offset := 0
if marker != "" {
	if n, err := strconv.Atoi(marker); err == nil { offset = n }
}

All five relevant AWS pages document the parameter positionally, in identical words: "the response includes only records beyond the marker, up to the value specified by MaxRecords". An offset diverges from that in two ways a caller can observe over the wire.

1. A record removed behind the cursor loses a record the caller never sees. Paging five instances two at a time and deleting the first after page one, page two was answered as items[2:] of a now-four-record listing, so the third record was never reported. The caller's loop terminated normally with four of five records and nothing to indicate the fifth had been skipped. A record created behind the cursor repeated one instead.

2. A Marker substrate never issued was answered with page one. strconv.Atoi's error was discarded, so any unparseable marker became 0. A consumer that persisted a marker across a restart, or truncated one, silently restarted its walk.

The fix

emulator/query_marker_pagination.go is one new file holding the whole contract, so the three sites cannot drift. The Marker now names the last record of the previous page and the next page is the records sorting strictly after it — the key-valued-cursor pattern ListBuckets' continuation-token already uses (s3_list_buckets.go). Consequences:

  • The marker is base64, so one substrate did not issue is detectable and is refused with InvalidParameterValue / 400 rather than served page one. That code is published for ElastiCache (on API_DescribeCacheClusters and API_DescribeReplicationGroups); the two RDS pages publish only their NotFound faults, so for RDS it is recorded in the doc comment as substrate's reading.
  • The marker is validated before any state is read, so a request substrate cannot serve is refused rather than answered.
  • Truncation is decided on the next matching record rather than on the page filling up, so a full last page carries no Marker and costs the caller no round trip to an empty page.

Lexicographic order itself remains substrate's reading — none of the five pages states an order. That is exactly why the cursor has to be key-valued: the guarantee is what makes "beyond the marker" well defined at all.

The audit (#887's actual scope)

All 128 non-test List call sites across 46 files were classified — not the ~60 the issue estimated:

Class Sites Meaning
A 50 Keys reach a response body; order is caller-observable
B 21 Keys reach a substrate control endpoint
C 57 Internal scan — single-key lookup, first-match mutation, or re-sorted before rendering

No new tier-1 operation exists. Eleven further AWS pages were read (RDS ×2, ElastiCache ×3, API Gateway GetRestApis, CloudWatch DescribeAlarms/ListMetrics, SSM DescribeParameters/GetParametersByPath, EC2's Query request page) and none publishes an ordering statement. EC2 is settled by a blanket disclaimer covering the whole family: "The order of the elements in the response, including those within nested structures, might vary. Applications should not assume that the elements appear in a particular order." ListMultipartUploads remains the only documented order in the tree.

Two corrections to #887's own body, both recorded on the issue: only one of ElastiCache's four describes has a cursor (describeReplicationGroups, describeCacheSubnetGroups and describeCacheParameterGroups implement no pagination at all — filed separately), and the site count is 128, not ~60.

Adjusted test, recorded as a finding

Per the issue's AC 5, TestElastiCachePlugin_CacheClusterPagination (emulator/elasticache_plugin_test.go) is not quietly relaxed. It asserted only that page one carried a <Marker>, then fetched page two with a hand-written "Marker": "2" and ended with _ = body — it never asserted anything about page two's contents, which is precisely why it passed against a cursor that dropped a record. It now walks the Marker page one actually returned and asserts page two's records and that they do not repeat page one's.

Tests

emulator/query_marker_pagination_test.go, wire-level only (no direct state writes):

  • the Marker equals base64("mk-db-1") and the last page carries none;
  • five instances paged two at a time with the first deleted after page one reports all five exactly once — the defect case; the old cursor never reported mk-db-2;
  • four records at MaxRecords=2: the full last page carries no Marker;
  • a marker substrate did not issue ("2", "mk-db-1!") answers 400 / InvalidParameterValue on both RDS describes and on ElastiCache;
  • DescribeDBClusters and DescribeCacheClusters page every record exactly once.

Not in scope

MaxRecords is left alone deliberately: substrate honours a value outside the documented 20–100 range and silently rewrites an unusable one. That is #913 — folding a page-size change into a page-contents change would have made the two indistinguishable in this diff and in any test that failed.

Verification

The nine-command gate is green, e2e included. Coverage 84.1% emulator / 83.6% total — baseline held.

)

DescribeDBInstances, DescribeDBClusters and DescribeCacheClusters
implemented Marker as a decimal offset into the sorted listing. All five
relevant AWS pages document the parameter positionally — "the response
includes only records beyond the marker, up to the value specified by
MaxRecords" — so an offset diverges from the published contract as soon as
the set changes behind the cursor: deleting a record already reported
shifted every later page and lost one the caller never saw.

The offset was also parsed with strconv.Atoi and the error discarded, so
any unparseable Marker became 0 and was answered with page one.

The Marker now names the last record of the previous page and the next page
is the records sorting strictly after it, the pattern ListBuckets'
continuation-token already uses. It is base64, so a marker substrate did
not issue is refused with InvalidParameterValue/400 — published for
ElastiCache, recorded as substrate's reading for RDS. Truncation is decided
on the next matching record, so a full last page carries no Marker.

Closes #887.
@codecov

codecov Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.00000% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/rds_plugin.go 91.30% 4 Missing ⚠️
emulator/elasticache_plugin.go 88.23% 2 Missing ⚠️
emulator/query_marker_pagination.go 97.29% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit b8f83e1 into main Sep 16, 2026
17 checks passed
@scttfrdmn
scttfrdmn deleted the fix/query-marker-cursor-basis branch September 16, 2026 00:21
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.

Audit the remaining ~60 List call sites for an AWS-documented order that differs from lexicographic

1 participant