Skip to content

fix(server,scripts): linger after H2 GOAWAY and flush guard logs - #1664

Merged
overtrue merged 2 commits into
mainfrom
p9/1421-1619-h2-linger-and-guard-budget
Nov 27, 2026
Merged

overtrue merged 2 commits into
mainfrom
p9/1421-1619-h2-linger-and-guard-budget

Conversation

@overtrue

Copy link
Copy Markdown
Collaborator

Summary

Fixes two live reproducible macOS test/guard defects observed on origin/main (678cb302):

  1. HTTP/2 protocol-error lingering close (crates/server): On 678cb302, conn::h2::tests failed 2/5 runs on c-h2-0007 (expected eof, observed reset), and a new deterministic socket test reproduced accepted=46/74, drained=0. After Hyper flushes an HTTP/2 error GOAWAY (error_code != 0), ProgressIo::poll_shutdown could see Poll::Pending before a pipelined HEADERS frame landed and return immediately (!linger.started && !linger.body_unfinished), closing the socket so arriving bytes triggered TCP RST; any Hyper error path that dropped the transport without calling poll_shutdown also skipped lingering close. This PR adds a zero-allocation H2OutboundGoAwayTracker in crates/server/src/preface.rs, wires it through ProgressIo::poll_write, poll_write_vectored, poll_shutdown, and linger_on_pending in crates/server/src/io.rs, and reclaims unshut transports via ReclaimableIo in crates/server/src/conn.rs. HTTP/1.1 traffic, graceful GOAWAY(NO_ERROR), and connections whose peer already sent EOF do not enter protocol-error linger.
  2. Guard-stage baseline-elapsed budget and live worker diagnostics (scripts/test_guard_scripts.sh): On 678cb302, running bash scripts/test_guard_scripts.sh under load took 503.33s (-13s of its 480s CI budget left) because shard workers reset SECONDS=0 after make_sandbox setup and the parent buffered all worker logs until every worker exited, erasing progress if the outer verify --all timer sent SIGKILL. This PR validates GATEWAY_GUARD_BUDGET_ELAPSED, forwards baseline_elapsed to workers so GUARD_BUDGET_STOP accounts for the full stage clock (and stops before spawning workers if baseline setup already exhausted GUARD_BUDGET_STOP), flushes each worker's log immediately upon exit, and adds a GUARD_BUDGET_SECONDS - 10 parent watchdog that prints unfinished workers' last ledger ordinals and partial logs before terminating them.

Closes #1421
Closes #1619
Closes #1465

Mutation Proofs

Every new assertion was verified red against targeted mutations before committing:

  • HTTP/2 lingering close (crates/server, 5/5 red):
    • M-H1-disable-linger-on-error-goaway: disabled linger_on_pending() returning true after error GOAWAY -> lingering_close::an_http2_protocol_error_with_unread_trailing_frames_ends_in_a_close_and_not_a_reset failed (rc=101).
    • M-H2-skip-vectored-outbound-observe: skipped observe_outbound_bytes in poll_write_vectored -> io::tests::h2_error_goaway_via_vectored_write_reclaims_unshut_transport failed (rc=101).
    • M-H3-treat-no-error-goaway-as-error: marked GOAWAY(NO_ERROR) as protocol-error -> io::tests::n_h2_no_error_goaway_does_not_linger_when_pending failed (rc=101).
    • M-H4-drop-is-http2-wire-guard: dropped is_http2_wire() guard in observe_outbound_bytes -> io::tests::n_http1_response_containing_goaway_bytes_never_triggers_h2_linger failed (rc=101).
    • M-H5-drop-peer-ended-guard: dropped !self.peer_ended guard in needs_protocol_error_linger() -> io::tests::n_h2_error_goaway_after_peer_eof_does_not_request_reclaim_linger failed (rc=101).
  • Guard budget clock & diagnostics (scripts/test_guard_scripts.sh, 5/5 red in isolated temp copies):
    • M-G1-drop-elapsed-env-validation: bypassed non-negative integer check on GATEWAY_GUARD_BUDGET_ELAPSED -> test_guard_budget_diagnostics.py failed on invalid -1 input (rc=1).
    • M-G2-drop-baseline-elapsed-forwarding: forwarded GATEWAY_GUARD_BUDGET_ELAPSED=0 to workers -> test_guard_budget_diagnostics.py failed (worker must stop when baseline + worker seconds >= stop, rc=1).
    • M-G3-drop-baseline-precheck: bypassed baseline_elapsed >= GUARD_BUDGET_STOP check -> test_guard_budget_diagnostics.py failed (rc=1).
    • M-G4-buffer-worker-output-until-all-done: removed immediate worker log flush on exit -> test_guard_budget_diagnostics.py failed (rc=1).
    • M-G5-disable-parent-watchdog: disabled SECONDS >= parent_stop watchdog -> stalled-worker test timed out as expected.

Verification

Four-command gate and targeted checks executed on macOS arm64 (CARGO_INCREMENTAL=0 CARGO_PROFILE_DEV_DEBUG=0 CARGO_PROFILE_TEST_DEBUG=0 CARGO_BUILD_JOBS=4):

$ cargo fmt --all --check
(exit 0, 8.52s)

$ cargo clippy --workspace --all-targets -- -D warnings
    Finished `dev` profile [unoptimized] target(s) in 6.40s
(exit 0, 7.05s)

$ cargo test --workspace
(exit 0, 703.50s; 11,834 passed; 0 failed; 3 ignored across 81 test summaries)

$ cargo xtask verify --crate rustfs-gateway-server
verify: crate rustfs-gateway-server runtime scope; thousand-connection load contracts remain in cargo test --workspace build compiled 24 crate(s) in 26.69s outside the budget
verify: crate rustfs-gateway-server runtime scope; thousand-connection load contracts remain in cargo test --workspace passed in 15.67s
(exit 0, complete wall 44.81s; prepared loop 15.67s <= 30s, 0 timed compilations)

$ for i in $(seq 1 20); do cargo test -p rustfs-gateway-conformance --lib conn::h2::tests; done
20/20 runs passed (0 failures; compared to 3/5 pass / 2/5 c-h2-0007 reset failures on 678cb302)

$ python3 scripts/test_guard_budget_diagnostics.py && python3 scripts/test_guard_group_baseline.py
test_guard_budget_diagnostics: 7/7 cases passed (6 negative, 1 positive)
test_guard_group_baseline: passed

No CI jobs were added; PR gate wall-clock budget impact is neutral (one 325-line Python guard self-test added as a shard_case, running in ~2s inside an existing shard worker).

Role Verdicts

  • simplicity-adversary: attacked H2OutboundGoAwayTracker frame-state transitions, ReclaimableIo drop-reclaim shutdown path, and run_guard_shards watchdog/budget-clock plumbing for unnecessary abstractions or over-broad hooks — no break found

Breaking Change

  • BREAKING — this PR touches a protected file or changes a public contract.

Checklist

  • The four-command gate passed (fmt, clippy, test, cargo xtask verify)
  • New or changed public API has rustdoc
  • Negative test cases outnumber positive ones
  • Every new assertion was mutated — the implementation was broken on purpose and the assertion
    went red. The PR description names which ones
  • No Protected File touched; if one was, the PR description contains BREAKING and a migration path
  • No unsafe introduced
  • No inventory / linkme introduced
  • No #[non_exhaustive] added to a DTO
  • No s3s code copied; behavioural evidence is URL + self-written summary
  • No credentials, signatures, or expected-signature values reachable from logs or error bodies
  • No plan document, analysis report, or working note committed
  • Commits follow Conventional Commits; PR title ≤72 characters
  • A Handoff comment has been appended to the issue

Track outbound HTTP/2 error GOAWAY frames (error_code != 0) in ProgressIo so poll_shutdown waits through LINGER_QUIET to drain late-arriving pipelined frames instead of dropping the socket into TCP RST, and reclaim ProgressIo if Hyper exits without shutting down. Resolves the intermittent c-h2-0006/0007 reset failures tracked in #1421 without touching frozen conformance schemas or weakening assertions.
Pass baseline preparation elapsed seconds to guard shard workers so GUARD_BUDGET_STOP fires relative to the full stage budget, fail early if baseline setup exhausts the stop threshold, flush completed worker logs immediately, and add a pre-SIGKILL parent watchdog reporting stalled workers and their last ledger ordinals. Resolves the timeout-diagnostic and budget-clock defects tracked in #1619 and #1465.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant