Skip to content

fix: wait for a macOS local socket in poll before every read and end four hided flakes - #1860

Merged
yansfil merged 7 commits into
mainfrom
fix/flaky3-hided
Oct 30, 2026
Merged

yansfil merged 7 commits into
mainfrom
fix/flaky3-hided

Conversation

@yansfil

@yansfil yansfil commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Closes with-hide/hide-private#351
Closes with-hide/hide-private#321
Closes with-hide/hide-private#347
Closes with-hide/hide-private#330
Related: with-hide/hide-private#339 (diagnostics only; the issue stays open)

Summary

Five flaky hided tests, one cause each:

Review

  • 판단해 주세요: a macOS-only poll before every local-socket read, against the kernel's lost wakeup, instead of changing each caller that waits for a peer's end.
  • 조심해서 볼 파일: hide-platform/src/ipc.rs - high-frequency path: every LocalStream read on macOS (Herdr socket, mux, pane service).
  • 조심해서 볼 파일: hided/tests/it/support/shipped.rs - shared state across test processes: lock, half-made copy cleanup, eviction of an older build.
  • 질문: link_mux's end tells the link's user by shutting down its end of an in-process pair, which a Windows peer does not hear until the handle closes, and no link_mux test runs on Windows. Should that become its own issue?
  • 비용 검토: one poll(2) per macOS read, with no new thread, timer, queue or notification. Linux and Windows read paths are unchanged (cfg!(target_vendor = "apple")). The mux frame reader sits behind a BufReader, so a frame is not one read per field.

Evidence

  • 확인한 것: PRD: 프로젝트별 Overview 제거와 프로젝트 행의 마지막 체크아웃 열기 #351 reproduced before the fix: the_connection_ending_frees_every_stream failed in 1 of 13, 1 of 81 and 1 of 141 stress iterations (both signatures). A stack sample showed the core's demux thread asleep in recvfrom after its peer ended.
  • 확인한 것: the kernel behaviour, in C at load ~30 on macOS 15.1: recv after the peer's shutdown(SHUT_WR) hung for over 60 s, about once in 4,500 rounds. A poll wait hung 0 times in 48,000 rounds, and close() 0 times in 18,000.
  • 확인한 것: the new contract test a_shutdown_ends_the_peers_blocked_read_every_time hung in recvfrom on its first iteration before the fix. Its rounds now run in an owned exact-test subprocess bounded to 60 s. With the macOS poll removed again, it failed at stress iteration 12 (round 3,724) in 10 s, with the subprocess reaped. With the fix: 75 runs × 5,000 rounds passed, and the link_mux tests passed 300 of 300 stress iterations (before the drain's failure-path change, which only touches a timeout).
  • 확인한 것: device_bootstrap passed 6 of 6 twice locally at 8 threads (macOS, private sshd and pinned Herdr 0.9.5). The store held one stripped copy, rebuilt once when the build changed.
  • 확인한 것: hide-platform + hided (lib and it) 971 tests and herdr-core + hide-herdr-client 3,496 tests passed on macOS with the change. Clippy -D warnings and fmt are clean.
  • 확인한 것: the new contract is Unix only: on the first CI run, os contract (windows) showed that a Windows shutdown never reaches the peer (CancelIoEx ends this end's own I/O; the peer hears the end when the handle closes).
  • 확인하지 못한 것: i18n 적용과 영어·한국어·중국어·일본어 기본 지원 #339's cause (no WSL here). wsl_device.rs is Windows-only; a cross-check from macOS could not build its C dependencies, so the windows wsl lane is its first compile.
  • 확인한 것 (비용, 미시): a C microbenchmark of plain recv vs poll+recv on one socketpair (macOS 15.1, load 18-48), not a product build. 64 B messages × 300,000: recv 1.14-5.87 µs per read over 5 completed trials, poll+recv 1.61-6.71 µs over 9. The difference within a matched pair was 0.3-1 µs; 2 more recv trials hung on the lost wakeup. 16 KiB × 20,000, 6 trials each: 5.7-17.8 µs vs 6.4-16.4 µs, with the pairs disagreeing in sign (noise).
  • 확인하지 못한 것 (비용, 실사용): docs/PERFORMANCE_TESTING.md's matched idle/driven terminal measurement (scripts/web-shell-measure, MEASURE_SCENARIO=keys: key echo p50/p95, hided CPU and RSS, base a891332 vs this head). It was not run: two release builds do not fit on this Mac's disk now, and its load is 20-60. The microbenchmark does not prove the product's end-to-end cost.
  • 확인하지 못한 것: core_move and remote_delivery with the shared helper (left to the remote mailbox lane).
Verification record

A recv blocked on a local socket on macOS sometimes sleeps through its
peer's shutdown, and then through its own end's too, while poll wakes
for both. A link_mux connection whose node ended kept its core-side
streams for good that way. Every macOS read now waits in poll first, as
a read with a timeout already did; Linux and Windows reads are unchanged.

Refs with-hide/hide-private#351
macOS refuses SO_RCVTIMEO once the stream has ended at the server, which
is the end the test waits for, so the read runs on a thread of its own
under a hang guard instead.

Refs with-hide/hide-private#351
…ixtures

Five device_bootstrap tests that each copied and stripped the 140 MB
debug hided at once ran past the fixture's 10 s command bound. The
remote_delivery, core_move and device_bootstrap fixtures now take a
shipped copy that the first test process strips and signs under a lock,
and each test gets a byte copy of its own.

Refs with-hide/hide-private#321
…ang guard

The lane's 120 s guard ended the reconnect journey saying nothing of
where it stood. The journey prints each step and the Hide AI request's
progress, and at 100 s prints its step and the distribution's processes.

Refs with-hide/hide-private#339
A Windows shutdown cancels this end's own reads and writes; its peer
hears the end when the handle closes, so the os contract (windows) leg
failed the new test at its first round.
The peer-shutdown rounds run in an owned, bounded exact-test subprocess,
since a read that missed its end cannot be woken in its process; the
link_mux drain shuts its socket and joins its reader before failing; the
shipped store reclaims half-made copies of every version and removes its
own on failure; the WSL journey keeps its record in memory and prints it
only on failure, with a ps bounded by an owned process.
…ling

The peer-shutdown rounds and the WSL journey's ps kept their owned child
only as a temporary, so a capture that could not confirm its end dropped
the handle; each now keeps it, ends and reaps it, and then reports the
original failure.
@yansfil
yansfil merged commit 08acd4a into main Oct 30, 2026
33 checks passed
@yansfil
yansfil deleted the fix/flaky3-hided branch October 30, 2026 04:07
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