Skip to content

fix(remote): avoid holding write handle on SSH evidence log on Windows - #200

Merged
xiaoyumuxi merged 1 commit into
mainfrom
fix/windows-ssh-evidence-sharing
Nov 25, 2026
Merged

xiaoyumuxi merged 1 commit into
mainfrom
fix/windows-ssh-evidence-sharing

Conversation

@xiaoyumuxi

Copy link
Copy Markdown
Contributor

Summary

Fixes Windows SSH remote connections failing immediately at stage=connect with:

Couldn't open logfile <HOME>\AppData\Local\Temp\lithe-evidence-...\ssh.log: Broken pipe

Root Cause

Introduced in 289af38 (#189): Evidence::new() pre-created %TEMP%\lithe-evidence-<suffix>\ssh.log with OpenOptions::new().read(true).write(true).create_new(true) and kept that writable File handle open while spawning ssh.exe -E <path>.

On Windows, Win32-OpenSSH's log_redirect_stderr_to opens the -E logfile without FILE_SHARE_WRITE. Because the parent process still held a writable handle on ssh.log, Windows rejected ssh.exe with ERROR_SHARING_VIOLATION (Win32 error 32), which MSVC CRT reports via strerror(32) as EPIPE (Broken pipe), causing ssh.exe to exit immediately with status 1.

Changes

  • rust/crates/workspace/src/ssh_evidence.rs:
    • Pre-create ssh.log with owner-only permissions (create_new(true)) and immediately drop the write handle so ssh.exe is the sole writer.
    • Open ssh.log read-only on demand in read_bounded for identity() and diagnostics() (on Windows, Rust defaults OpenOptions::new().read(true) to FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE).
    • Add unit test evidence_reads_diagnostics_and_identity_written_by_another_handle.
  • rust/crates/workspace/src/sessions.rs:
    • Move Evidence into ConnectionTransport::Process and drop it in Connection::end_transport() after tree.terminate(EXIT_GRACE), so Windows can cleanly delete lithe-evidence-* after ssh.exe exits rather than failing cleanup while ssh.exe holds ssh.log open.
  • rust/crates/git-host/src/authentication/windows.rs:
    • Use O:{sid}D:P(A;OICI;GA;;;{sid}) for private_directory so files created inside the private directory (including ssh.log) inherit the owner-only protected DACL.
  • rust/crates/platform-tests/tests/platform/permissions.rs:
    • Add Windows platform test private_directory_evidence_log_allows_read_only_sharing_with_single_writer simulating a writer opening ssh.log with FILE_SHARE_READ only (no FILE_SHARE_WRITE) while the host reads concurrently.

Verification

  • cargo fmt --manifest-path rust/Cargo.toml --check — passed
  • node scripts/rust-core/verify-platform-tests.mjs — passed (every test of 53 crates runs on a host CI tests it on)
  • scripts/rust-core/verify-rust-core-comments.sh git-host workspace platform-tests — passed
  • cargo test --manifest-path rust/Cargo.toml -p lithe-workspace -p lithe-git-host -p lithe-platform-tests — 136 passed, 0 failed (macOS)
  • LIBSQLITE3_SYS_USE_PKG_CONFIG=1 cargo clippy --manifest-path rust/Cargo.toml -p lithe-workspace -p lithe-git-host -p lithe-platform-tests --all-targets --target x86_64-pc-windows-msvc -- -D warnings — passed
  • Not run locally: Native Windows test execution (lithe-platform-tests on Windows) — no Windows VM on this macOS host; will run in Windows CI once marked ready.

@xiaoyumuxi
xiaoyumuxi marked this pull request as ready for review November 25, 2026 08:22
@xiaoyumuxi
xiaoyumuxi merged commit e892741 into main Nov 25, 2026
8 of 11 checks passed
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