sockrelay relays a Windows named pipe to a unix socket on the WSL side, so a Linux program can
talk to a Windows service listening on that pipe. It relays raw bytes both ways and parses nothing;
--pipe-path sets which pipe. It starts its Windows process once and carries every connection over
it, where a socat + npiperelay.exe bridge starts a Windows process per connection, and each of
those tries to open the pipe once: when every pipe instance is busy, the connection just fails.
The shipped units, install.sh and the rest of this README relay the Windows OpenSSH ssh-agent
pipe for Linux ssh, the pipe sockrelay has been tested against. Under parallel SSH (Ansible
forking many connections) that bridge fails with "communication with agent failed";
BENCHMARKS.md compares the two under load and traces each of those failures to a
busy pipe.
sockrelay-client(Linux) runs as a systemd user service on the unix socket systemd passes it (see Running). It startssockrelay-serveronce and carries each accepted connection over its own stream of oneyamuxconnection over the server's stdin and stdout. If that link is lost the client exits, and systemd restarts it.sockrelay-server(Windows, cross-compiled; WSL runs it natively) relays each stream to a fresh handle on the pipe, thessh-agentpipe in the example. It exits as soon as the client is gone, so it never outlives it.
Starting the server, the yamux connection, watching both ends, logging and systemd integration come
from librelay, shared with
credrelay, a relay of the same shape for the Windows
Credential Manager. What is left here is the relay: the socket on one side, the pipe on the other.
Windows named pipes have no half-close, so the server's relay ends a connection as soon as either
direction does, rather than waiting for both as tokio::io::copy_bidirectional does on the unix
side.
A load-testing tool used while developing this lives in its own repository,
sockrelay-loadtest.
Every flag has a default, so the systemd unit runs it bare:
sockrelay-client
--server-exe <PATH> default: sockrelay-server.exe, searched in PATH
--accept-error-backoff-ms <MS> default: 100
--pipe-path <PATH> default: \\.\pipe\openssh-ssh-agent (passed to the server)
--connect-timeout-secs <N> default: 5 (passed to the server)
--jitter-max-ms <MS> default: 50 (passed to the server)
The socket's path and mode belong to sockrelay.socket, not to a flag. The last three flags only
pass through to the server as arguments: environment variables don't cross the WSL interop
boundary into a Windows process.
Started by sockrelay-client, which passes every flag; every flag is required, so it never guesses.
By hand, against a real agent:
sockrelay-server.exe --pipe-path '\\.\pipe\openssh-ssh-agent' --connect-timeout-secs 5 `
--jitter-max-ms 50 --log-filter info--connect-timeout-secsbounds how long a connection waits for a saturated agent once the pipe answersERROR_PIPE_BUSY.--jitter-max-msis the random pause between busy retries, so waiters woken by the same freed pipe instance don't all retry at once.--log-filteris the server'stracingfilter (see Logging).
sockrelay runs under systemd, which needs systemd running in WSL (systemd=true under [boot]
in /etc/wsl.conf). install.sh installs two user units into $XDG_CONFIG_HOME/systemd/user
(~/.config/systemd/user by default):
sockrelay.socketbinds~/.ssh/agent.sock(mode0600) and starts the service on the first connection. It stays open while the service restarts, so a connection made meanwhile waits instead of being refused.sockrelay.servicerunssockrelay-clientasType=notifyon that socket, and restarts it 2 seconds after a failure.
systemctl --user enable --now sockrelay.socketstarts the relay on demand; enabling sockrelay.service too starts it with the session. The shell
profile only points SSH at the socket:
export SSH_AUTH_SOCK=~/.ssh/agent.socksystemd hears the service is ready only once the relay is known to work. sockrelay-server exits at
once if --pipe-path names no running agent, and sockrelay-client waits 500ms for the server to
prove it stays up, so a wrong pipe or a stopped agent fails the start rather than the first
connection. Any startup failure exits non-zero with its reason in the journal.
systemctl --user stop sockrelay stops gracefully, even while the service is still starting: the
client stops accepting, gives connections in flight up to 5 seconds, closes the link, and the
server exits on its own. A server still running 5 seconds later fails the stop, and systemd kills
it.
The client also exits non-zero, for systemd to restart it, if the socket it was passed stops
accepting connections for good; a transient accept() failure, such as running out of file
descriptors, is retried after --accept-error-backoff-ms.
For debugging, with the units stopped, systemd-socket-activate passes a socket the way the unit
does:
RUST_LOG=debug systemd-socket-activate -l "$XDG_RUNTIME_DIR/sockrelay-debug.sock" sockrelay-clientBoth processes log to the client's stderr, which systemd sends to the journal:
journalctl --user -u sockrelay- The filter is
RUST_LOG,infowhen unset or empty; set it for the service withsystemctl --user edit sockrelay.serviceandEnvironment=RUST_LOG=debugunder[Service]. An invalid one stops the client before it starts anything. - The client passes the same filter to the server as
--log-filter. - Each line the server writes is forwarded with a
server:prefix followed by a space. - On a terminal, both processes color and timestamp their lines. In the journal, which timestamps every line itself, neither adds a timestamp or color.
The server is cross-compiled for the host's own architecture with
cargo-xwin; WSL then runs the .exe natively, with no
emulation:
rustup target add aarch64-pc-windows-msvc
cargo install cargo-xwin
cargo build -p sockrelay-client
cargo xwin build -p sockrelay-server --target aarch64-pc-windows-msvcinstall.sh does this for the host's architecture and installs both release binaries into
/usr/local/bin and the units. Windows keeps running an .exe it already has open even after the
file is replaced, so once the new files are in, it stops the service and any server left running,
and starts the service again if it was running. It enables nothing and touches no shell config; it
prints the remaining steps:
./install.shEach release carries the client for Linux
(sockrelay-client-linux-amd64, sockrelay-client-linux-arm64, static musl builds) and the server
for Windows (sockrelay-server-windows-amd64.exe, sockrelay-server-windows-arm64.exe), with
their checksums in SHA256SUMS. Install them as sockrelay-client and sockrelay-server.exe on
PATH, then copy contrib/sockrelay.socket and contrib/sockrelay.service where install.sh puts
them, replacing @BINDIR@ with the directory holding sockrelay-client.
Run the Release PR workflow from the Actions tab. It opens chore: release vX.Y.Z with the
version git-cliff computes from the commits since the last tag and a regenerated CHANGELOG.md;
merging it tags the commit and publishes the release.
cargo test --workspace
cargo clippy --workspace --all-targets --all-features -- -D warningsclient/tests/socket_activated.rs runs the built client under systemd-socket-activate (from the
systemd package) against a stand-in server script, one of its tests short of file descriptors
under prlimit (from util-linux), so it needs both tools on PATH.
The server's pipe code only builds for Windows. Its tests run there, cross-compiled; WSL runs the test binary natively:
eval "$(cargo xwin env --target aarch64-pc-windows-msvc)"
unset CARGO_TARGET_AARCH64_PC_WINDOWS_MSVC_RUNNER
cargo test -p sockrelay-server --target aarch64-pc-windows-msvc
cargo clippy -p sockrelay-server --all-targets --target aarch64-pc-windows-msvc -- -D warnings(cargo xwin env sets the target's runner to wine, which isn't needed here, so it is unset.) The
client is unix-only, so only -p sockrelay-server builds for Windows.
- systemd creates the socket with
SocketMode=0600fromsockrelay.socket, before the client runs. - The relay never retries or respawns: if the link to the server is lost the client exits rather than masking it, and systemd restarts it.
- A saturated agent produces a bounded failure (
--connect-timeout-secs) rather than a hang or a silently retried request.
Licensed under either of Apache License, Version 2.0 or MIT license at your option.