Skip to content

fix(rsync): close the keepalive cancellation race (RIG-11982) - #251

Open
rigel-mintaka wants to merge 4 commits into
mainfrom
harness/rig-11982-close-the-keepalive-cancellation-race
Open

rigel-mintaka wants to merge 4 commits into
mainfrom
harness/rig-11982-close-the-keepalive-cancellation-race

Conversation

@rigel-mintaka

@rigel-mintaka rigel-mintaka commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

What does this do

Fixes the flaky rsync keepalive test. Its cancel now fires on the first keepalive frame, from the write path. Also, when the mux's timeout check sees a cancel and a due timeout in the same pass, it now returns the cancel.

Why do we need it

blocked_sender_sends_keepalives_instead_of_timing_out failed 2 of 8 times inside the full pi-builtins suite, even after nebula#221. A polling thread raced the 2 s timeout. Cancelling on a later keepalive was not enough either: the frame is only queued, so a timeout could be seen in the same pass before the write set cancel.

Summary

  • mux.rs: cancel_before_timeout at the two timeout checks that read a cancel flag (settle, read_data). A cancel is the side's first failure, so this cannot hide a real timeout.
  • Keepalive test: cancels on the first keepalive frame. At that check idle is under 1 s, so no timeout can fire in that pass. No thread, sleep or deadline.
  • New tests: a due keepalive is sent by check_timeout; cancel wins over a due timeout, and a timeout stays RERR_TIMEOUT without cancel.

Verification

On macpro2013, one staged build:

  • The keepalive test passed 20 of 20 full-suite runs (1.0–1.3 s).
  • With keepalive sending disabled, the test fails at 3.016 s (RERR_TIMEOUT).
  • cargo fmt --package pi-builtins and cargo clippy -p pi-builtins are clean.

Two review rounds; all-clear at the head. Two lows remain (test coverage only).

Step-up signal: the implement-rust run took 1 h 25 min, got 2 of 20 runs and no control. implement-hard-rust reached the cause in the product code, then fixed the review's remaining race.

Risks

A host cancel during a real timeout now reports a cancel, not a timeout. Rollback: revert this PR.

Spec impact

Spec-impact: none

Checks skipped: nebula has no pre-push hook config; GitHub Actions ci.yaml runs its checks

Refs RIG-11982

Co-authored-by: Matt Wilkinson matt@rigel.build

rigel-mintaka and others added 4 commits November 23, 2026 08:48
Refs: RIG-11982
Co-Authored-By: Matt Wilkinson <matt@rigel.build>

Co-authored-by: Matt Wilkinson <matt@rigel.build>
Refs: RIG-11982
Co-Authored-By: Matt Wilkinson <matt@rigel.build>
Refs: RIG-11982
Co-Authored-By: Matt Wilkinson <matt@rigel.build>
Refs: RIG-11982
Co-Authored-By: Matt Wilkinson <matt@rigel.build>
@linear-code

linear-code Bot commented Nov 23, 2026

Copy link
Copy Markdown

RIG-11982

@rigel-mintaka

Copy link
Copy Markdown
Contributor Author

Review rounds

Round 1 at f635651b: 0H / 1M / 3L.

  • M1: the keepalive is only queued, so the cancel-wins mapping did not close the race. Fixed in 25512a16: cancel on the first keepalive (idle is under 1 s, so no timeout in that pass).
  • L1: the precedence test also asserts that a timeout stays RERR_TIMEOUT without cancel. Fixed.
  • L2: MuxWriter::idle uses wait_for_lock=true; no change needed. Confirmed.
  • L3: (RIG-11982) in a commit subject. Fixed.

Round 2 at 25512a16 (interdiff): 0H / 0M / 2L, all-clear.

  • L1 (open, not gating): no test reaches the call-site mapping in settle/read_data.
  • L4 (open, not gating): the keepalive-check test uses timeout = u64::MAX, so it does not pin keepalive-before-timeout order.

Head ded402db is a rebase of 25512a16; the patch is identical (diff with index lines stripped).

@rigel-mintaka

Copy link
Copy Markdown
Contributor Author

All-clear at ded402d
Base: main

This branch had an error being deployed

1 failed deployment
ci — ded402db Deployed Nov 23, 2026 by rigel-mintaka via CI (aarch64-linux) #1185
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant