Repository navigation
fix(testaws): record a request before its caller can observe the response - #216
Merged
Merged
Conversation
…onse Everything in internal/testaws that asserts on transfer behavior reads the request log immediately after the operation it measures returns. That is only sound if a completed response implies a recorded request, and it did not: the handler appended to the log after proxy.ServeHTTP returned, while the proxy writes the response body to the socket inside that call. A client could hold every byte of a fully-Content-Length'd response whose request was not yet in the log. Measured at 45-70 of 640 concurrent ranged reads. The consequence landed in a different package. internal/fuse TestShortFileIsServedFromCache failed on its precondition -- "the first read issued no GET" -- which reads as the read path having served from a cache the fixture had just constructed empty, in a test whose whole subject is cache correctness. One CI run in seven, on 61b54e2, with the commits either side green. A harness whose observations lag the behavior it observes makes every assertion built on it a coin flip weighted by machine load, and the failure blames the code under test rather than the instrument. Requests are now published on arrival and their response fields filled in once served; snapshot and reset wait for anything still in flight, so every accessor inherits the guarantee rather than each one restating it. Documented on Fault that OnFire must not read the log -- the triggering request is counted in flight for the hook's duration, so it would wait on itself. Verified in both directions: the new test loses 45-70 of 640 requests against the previous recorder and zero against this one. Full suite green, 32 packages, -race.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The failure
CI failed on
61b54e2(the #96 merge) with the commits either side green. One test:That is the test's precondition, not its assertion. It reads as the FUSE read path having served
10240 bytes from a cache the fixture constructed empty two lines earlier — a cache-correctness test
reporting that the cache did something impossible.
What it actually was
internal/testawsproxies every request and logs it. The read-path suite asserts on that log —bytes transferred and GETs issued are how read amplification and cache behaviour get measured,
because neither the AWS SDK nor the emulator reports them.
The handler appended the log entry after
proxy.ServeHTTPreturned. The proxy writes theresponse body to the socket inside that call, so the sequence was:
bytes.EqualpassesGETs("small.dat")→ emptyThe bytes compared equal because the GET did happen. It just wasn't recorded yet.
Diagnosis
By elimination first — the read returned correct bytes, and the fixture's cache was new, so the GET
must have reached the endpoint — then reproduced directly: 45–70 of 640 concurrent ranged reads
observed an empty GET log against the previous recorder.
Concurrency is required to see it. The window is between two statements on one goroutine, so a
single caller alternating request and assertion never lands in it; my first two standalone
reproductions returned 0/6000 for exactly that reason.
Fix
Publish the request on arrival, fill in its response fields once served, and have
snapshotandresetwait for anything still in flight. Waiting insnapshotmeans every accessor built on itinherits the guarantee instead of each one restating it.
resetwaits for the mirrored reason: clearing mid-flight leaves a request in the log after thereset meant to precede it, so the next assertion counts traffic from the phase the test just
declared finished.
Documented on
FaultthatOnFiremust not read the log — the triggering request is counted inflight for the hook's duration, so a hook that read it would wait on itself. Neither existing hook
does; both only issue requests, which is fine.
Verification
Both directions, because a regression test that cannot fail proves nothing:
git show HEAD:)go test -race -count=1 ./...— 32 packages, 0 failuresTestShortFileIsServedFromCache× 60 underGOMAXPROCS=2— cleaninternal/testaws× 15 — cleangolangci-lint run --new-from-merge-base=origin/main— 0 issuesgofmt -l— emptyWhy this one matters more than its size
The audit's premise is that 32,680 lines of tests missed ~45 defects because mocks agree with their
callers by construction.
internal/testawsexists to remove that. A harness whose observations lagthe behavior it observes reintroduces the same problem in a new shape: the assertion becomes a coin
flip weighted by machine load, and when it loses, it blames the code under test.