Skip to content

Fix timing flake in proxy_serve_stale_dns_fail - #13869

Merged
bryancall merged 4 commits into
apache:masterfrom
bryancall:proxy-serve-stale-dns-fail-flake
Oct 26, 2026
Merged

bryancall merged 4 commits into
apache:masterfrom
bryancall:proxy-serve-stale-dns-fail-flake

Conversation

@bryancall

@bryancall bryancall commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

test_proxy_serve_stale_dns_fail asks each proxy for a stale copy 7 seconds after pushing it, under a single 15 second stale limit, so the "serves stale" responses have only 8 seconds of headroom. When the machine running the test stalls longer than that, the proxy correctly answers 500 Cannot find server instead of the expected 200 and the output check fails. CI hit this failure on busy agents in the AuTest version of this test, and again on the Uranium version after #13545 moved it there.

This gives the two kinds of checks their own stale window. Both proxies now allow 300 seconds, so a late request can no longer turn a "serves stale" response into a 500. The requests that expect a copy to be too old send X-Stale-Window: narrow, and a header_rewrite set-config rule on the localhost maps shrinks proxy.config.http.cache.max_stale_age to one second for that request only, so lateness only makes those responses more certain. The header is not part of the cache key, so every request still reads the same cached copy, and the child's second request still checks that a copy rewritten by negative revalidation expires by its max-age. The two 17 second waits become one 7 second wait, and the test drops from about 51 seconds to about 24.

Testing, with the Uranium runner on a Fedora 44 host: pausing the test for 20 seconds before the first check fails master 4 of 4 times with the CI signature. This change passes 4 of 4 with a 20 second pause and 4 of 4 with a 40 second pause. Setting the wide window to one second, setting the narrow window to 300 seconds, or not sending the header each make the new test fail 3 of 3 times, so every check still discriminates.

The test asked each proxy for a stale copy 7 seconds after pushing it,
under a single 15 second stale limit, so the "serves stale" responses
had only 8 seconds of headroom. A CI agent that stalls longer than that
gets a correct 500 instead of the expected 200, and the gold file
mismatches.

Give the two kinds of checks their own stale window. The proxies now
allow 300 seconds, so lateness cannot turn a "serves stale" response
into a 500. Requests that expect a copy that is too old send
X-Stale-Window: narrow, and a header_rewrite set-config rule shrinks
max_stale_age to one second for that request only, so lateness only
makes those responses more certain. Every request still reads the same
cached copy, so the child's second request still checks that a copy
rewritten by negative revalidation expires by its max-age. The 17
second waits go away and the test drops from about 56 seconds to about
28.
Copilot AI balanced review requested due to automatic review settings October 19, 2026 21:50
@bryancall bryancall added this to the 11.0.0 milestone Oct 19, 2026
@bryancall bryancall self-assigned this Oct 19, 2026
@bryancall
bryancall requested a review from traeak October 19, 2026 22:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

No open issues 🎉

What changed in this PR

Adjusts proxy_serve_stale_dns_fail to eliminate timing-related flakes on slow CI agents by separating “serve stale” vs “too old” validations into distinct stale windows while reducing overall test runtime.

Changes:

  • Introduces wide vs narrow stale windows (300s vs 1s) and toggles behavior per-request via X-Stale-Window: narrow.
  • Applies per-request proxy.config.http.cache.max_stale_age narrowing using header_rewrite set-config rules in remap.
  • Removes long sleeps and updates timing to keep assertions deterministic while cutting runtime roughly in half.
File Description
tests/​gold_tests/​cache/​proxy_serve_stale_dns_fail.test.py Adds per-request stale-window control via header_rewrite and adjusts sleeps to prevent timing flakes and reduce test duration.

Review effort: Lite

traeak
traeak previously approved these changes Oct 19, 2026

@traeak traeak left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Approve. The fix addresses the root cause of the flake: the serve-stale checks and the too-old checks shared one 15 second window, so CI stalls flipped the expected 200s into 500s. Splitting them into a 300 second default window and a 1 second per-request window (via header_rewrite set-config on the overridable proxy.config.http.cache.max_stale_age) makes delay harmless for the serve-stale checks and only strengthens the too-old checks. The reasoning matches the core logic in HttpTransact::is_stale_cache_response_returnable and the negative revalidation path, which rewrites the cached copy with a new Expires but keeps max-age=5, so the copy's age restarts. Verified locally: the test passes in about 28 seconds (down from about 56); widening the narrow window to 300 makes it fail, so the narrow checks still catch failures; inserting a 20 second stall before both serve-stale requests (the original flake scenario) still passes.

Positive Notes

  • Fixes the cause instead of padding sleeps, and cuts runtime roughly in half.
  • The comments explain the stale window design and why the child's second request still needs its 7 second wait.
  • Thorough testing in the description: stall injection, mutations to confirm the checks still catch failures, and sanitizer builds.

Recommendation

Approve - the code looks good. Minor items can be addressed optionally.

@traeak

traeak commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

One optional note on X-Stale-Window: the child's narrow request forwards that header to the parent, where it matches map http://unknown.domain.com/ http://unknown.domain.com/. That rule doesn't load header_rewrite, so the parent keeps the 300 second window for it. This works because the parent has no usable copy under that key, which the expected 500 confirms. A one-line comment saying the narrow window only applies on the proxy the client talks to directly would help the next reader.

Copilot AI balanced review requested due to automatic review settings October 19, 2026 23:32
@bryancall

Copy link
Copy Markdown
Contributor Author

Thanks, good catch. I added the comment in e50f965: only the localhost maps load the rule, so the narrow window applies on the proxy the client talks to directly, not on the parent the child forwards to.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused test changes preserve the intended coverage, with no unresolved findings.

No open issues 🎉

Review effort: Balanced

@bryancall

Copy link
Copy Markdown
Contributor Author

[approve ci autest 1]

traeak
traeak previously approved these changes Oct 20, 2026
…ns-fail-flake-local

# Conflicts:
#	tests/gold_tests/cache/proxy_serve_stale_dns_fail.test.py
The AuTest this pull request fixed was converted to Uranium on master.
Carry the same fix into tests/uranium_tests/cache: a 300 second stale
window for the checks that expect a stale copy, and a header_rewrite
rule that narrows it to one second for the requests that expect a copy
to be too old, in place of the 17 second sleeps.
Copilot AI balanced review requested due to automatic review settings October 21, 2026 02:43
@bryancall

Copy link
Copy Markdown
Contributor Author

#13545 moved this test to Uranium, so I merged master and moved the fix into tests/uranium_tests/cache/test_proxy_serve_stale_dns_fail.py. The mechanism is the same as before: max_stale_age is 300 on both proxies, and the two checks that expect a copy to be too old send X-Stale-Window: narrow, which a header_rewrite rule on the localhost maps turns into a one-second window for that request. The 17 second sleeps are gone. The AuTest file this PR used to edit no longer exists, so the diff is now only the Uranium file.

I reran the proof against the Uranium test:

Test Change Failed
master none 0/4
master 20 s stall before the first check 4/4 (500 where 200 is expected)
this PR none 0/4
this PR 20 s / 40 s stall 0/4 / 0/4
this PR wide window set to 1 s 3/3
this PR narrow window set to 300 s 3/3
this PR X-Stale-Window header not sent 3/3

Could you take another look?

@bryancall
bryancall requested a review from traeak October 21, 2026 02:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

2 open issues

Review effort: Lite

@bryancall

Copy link
Copy Markdown
Contributor Author

CI hit this on the Uranium version this morning: autest build 45685 on #13880, which only changes HttpSessionManager.cc. The responses were 500, 500, 200, 500 where the gold file expects 200 first, the same signature as the AuTest failures, so the move to Uranium did not make it go away.

@traeak traeak left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks the same as before when approved.

@bryancall
bryancall merged commit 701bda1 into apache:master Oct 26, 2026
14 checks passed
@cmcfarlen cmcfarlen moved this to For v10.2.2 in ATS v10.2.x Nov 3, 2026
cmcfarlen pushed a commit that referenced this pull request Nov 3, 2026
The serve-stale checks and the too-old checks shared one 15 second stale limit,
and the test asked for a stale copy 7 seconds after pushing it, so a CI agent
that stalled for more than 8 seconds got a correct 500 instead of the expected
200. Each kind of check now has its own window: the proxies allow 300 seconds,
and requests that expect a too-old copy send X-Stale-Window: narrow, which a
header_rewrite set-config rule turns into a one second max_stale_age for that
request only. The two 17 second sleeps become one 7 second wait.

(cherry picked from commit 701bda1)
@cmcfarlen cmcfarlen modified the milestones: 11.0.0, 10.2.2 Nov 3, 2026
@cmcfarlen cmcfarlen moved this from For v10.2.2 to Picked v10.2.2 in ATS v10.2.x Nov 3, 2026
@cmcfarlen

Copy link
Copy Markdown
Contributor

Cherry-picked to the 10.2.x branch as e3225a4 for the 10.2.2 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Picked v10.2.2

Development

Successfully merging this pull request may close these issues.

4 participants