Skip to content

Fix h2_to_origin_safe_retry flakes from abrupt origin closes - #13834

Open
bryancall wants to merge 1 commit into
apache:masterfrom
bryancall:h2-safe-retry-flake
Open

bryancall wants to merge 1 commit into
apache:masterfrom
bryancall:h2-safe-retry-flake

Conversation

@bryancall

Copy link
Copy Markdown
Contributor

h2_to_origin_safe_retry, added in #13447, fails now and then in autest shard 1of4, usually with a 502 to the client. The failures come from how the test's Python origin, safe_retry_origin.py, ends its connections, not from ATS.

The origin closed its socket as soon as it wrote its last frame. ATS often has a SETTINGS ACK in flight at that point, and closing a socket that still holds unread input makes Linux reset the connection, which can drop the response the origin just wrote. The goaway, goaway-reserved, goaway-drain-above and early-rst retries failed this way on a busy machine. The origin now shuts down its sending side and reads until ATS closes before it closes the socket. It does this on a background thread so it can still accept the new connection ATS opens for a retry.

The early-rst origin also closes its connection right after the reset. ATS can take that session back from the pool for the retry before it reads the close, and it then correctly declines to replay a POST written to a connection that closed without a response. That scenario now sets server_session_sharing.match to none, so its retry always opens a new connection. The other scenarios keep ip matching and still cover a retry on a reused connection.

Testing: in the ci.trafficserver.apache.org/ats/fedora:44 image, with 32 copies of the test running in parallel, master failed 39 of 640 runs on one machine, and 135 of 800 on a second machine with CPU load added. With this change it failed 0 of 640 and 0 of 800, although ATS admitted the early-rst retry before reading the origin's close in 596 and 437 of those runs. To check that the test still catches a broken retry, I built ATS so it never admits a not-processed retry. The changed test failed on that build in all 4 runs, on the same 12 checks as the original test.

The custom HTTP/2 origin in h2_to_origin_safe_retry closed its socket as
soon as it finished with a connection, and two races made retry
scenarios fail with a 502 when the machine was busy.

When the origin closed a connection that still held unread input,
usually the SETTINGS ACK that ATS sends after the request, the kernel
reset the connection and the response the origin had just written never
reached ATS. The goaway, goaway-reserved, goaway-drain-above and
early-rst retries failed this way. The origin now half-closes and reads
until ATS closes before it closes the socket.

The early-rst origin also closes its connection right after the reset.
ATS can take that session back from the pool for the retry before it
reads the close, and it then correctly declines to replay a POST written
to a connection that closed without a response. That scenario now
disables session sharing, so its retry always opens a new connection.
Copilot AI balanced review requested due to automatic review settings October 13, 2026 21:11
@bryancall bryancall added this to the 11.0.0 milestone Oct 13, 2026
@bryancall bryancall self-assigned this Oct 13, 2026

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 findings
What changed in this PR

Stabilizes the h2_to_origin_safe_retry autest by updating the test origin’s connection teardown to avoid Linux RST-on-close behavior and by forcing the early-rst scenario to avoid reusing a just-closed origin session.

Changes:

  • Add a “half-close + drain reads” connection-finisher in safe_retry_origin.py and run it on a background thread so the origin can accept retry connections promptly.
  • Update the early-rst test configuration to disable origin session reuse via server_session_sharing.match = none.
File Description
tests/​gold_tests/​h2/​safe_retry_origin.py Drain/finish TLS connections safely and asynchronously to prevent spurious resets during retries.
tests/​gold_tests/​h2/​h2_to_origin_safe_retry.test.py Ensure early-rst retries always use a fresh origin connection to avoid “closed-before-read” reuse.

🧠 Review effort: Lite


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tests/gold_tests/h2/safe_retry_origin.py
Comment thread tests/gold_tests/h2/safe_retry_origin.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants