Repository navigation
fix(middleware): don't re-run a coalesced flight in the caller that executed it - #887
Open
ashinpaugh wants to merge 2 commits into
Open
ashinpaugh wants to merge 2 commits into
ashinpaugh wants to merge 2 commits into
Conversation
…xecuted it singleflight reports shared=true to every caller of a flight that had waiters, including the one that executed it, so a private (or Set-Cookie) result made the executing caller run the handler a second time into its own response: duplicated headers, sometimes a second body, N+1 upstream calls. Only callers that waited now re-run. Fixes darkweak#886
✅ Deploy Preview for teal-sprinkles-4c7f14 canceled.
|
Each upstream now runs on its own httptest server, closed when the test ends. The fixed ports were never released, so a repeated run (-count) reached the previous run's upstream and the call counter read 0.
Author
|
Verification run against master (7f62bbb), mirroring this repo's CI (
Follow-up commit: the test's upstreams now run on |
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.
Fixes #886.
singleflightreportsshared=trueto every caller of a coalesced flight, including the caller that executed it.Upstream()re-runs the handler forshared && sfWriter.disableCoalescingso that waiters don't reuse aprivate/Set-Cookieresult, but the same branch also fired for the executing caller, which then rannexta second time into its ownCustomWriter. SinceCustomWriter.Header()is the client's header map, one response ended up with every upstream header twice (and sometimes a second body), and the upstream was called N+1 times.This records whether the current caller executed the flight (set inside the
DoChancallback; the channel receive orders that write before the read) and skips the re-run for it. Waiters behave as before.Test:
plugins/caddy/doubled_body_test.goruns Caddy with the cache and an upstream that adds its headers, stamps a uniqueX-Request-Id, sleeps 80ms and returns one JSON document. 8 concurrent identical requests per case, asserting oneContent-Type, oneX-Request-Id, a single JSON body and one upstream call per request, for aprivateresponse and a public one.go test -race -count=1 -run TestConcurrent ./plugins/caddypasses.want exactly one Content-Type, got ["application/ld+json" "application/ld+json"],the origin ran 2 times into ONE response (X-Request-Id ["exec-1" "exec-8"]), andwant the origin called once per request (8), got 9.Not included: the global
disable_coalescingoption is not copied into the handler config byFromApp(noted in #886), left for a separate change.