8000 feat(bridge): listen on a Unix socket with --unix and name consomme in the --wsl refusal by stlindenau · Pull Request #479 · amirlehmam/wmux · GitHub
[go: up one dir, main page]

Skip to content

feat(bridge): listen on a Unix socket with --unix and name consomme in the --wsl refusal - #479

Merged
amirlehmam merged 2 commits into
amirlehmam:masterfrom
stlindenau:bridge-unix-socket
Nov 27, 2026
Merged

amirlehmam merged 2 commits into
amirlehmam:masterfrom
stlindenau:bridge-unix-socket

Conversation

@stlindenau
Copy link
Copy Markdown
Contributor

Summary

  • wmux bridge --unix <path>: the bridge listens on a Unix socket on the distro's own filesystem instead of a TCP port. A container gets the socket's directory bind-mounted and sets WMUX_PIPE and WMUX_PIPE_TOKEN. Clients need no change, since connectTransport and wmux-hook.js already dial a Unix socket when WMUX_PIPE starts with /.
  • --wsl now recognises consomme (formerly virtioproxy) and refuses it by name, pointing at --unix <path> or --host <addr>, instead of the misleading "could not determine this distro's networking mode".

Why

Under networkingMode=virtioproxy/consomme, wslinfo --networking-mode is neither nat nor mirrored, so --wsl exits and the container gets no wmux. --host is no workaround on WSL 3.0.5 (bind() fails with EINVAL, microsoft/WSL#42223, fixed by microsoft/WSL#42230), and what a 0.0.0.0 listener exposes under consomme is undocumented.

This is not the cross-boundary socket docs/DEVCONTAINER.md says was tried first: that one lived on the Windows side and 9P does not forward AF_UNIX. Here a process in the distro creates the socket and a container on the same kernel uses it; paths on a 9P mount (/mnt/<drive>) are refused.

Safety rules (pure module bridge-unix.ts)

  • not combinable with --host, --wsl or --port
  • absolute path, at most 107 bytes, not the pipe being relayed to
  • parent directory exists and is not group- or world-writable
  • socket created under umask 077 and chmod 0600
  • a socket nobody listens on (ECONNREFUSED) is replaced; a live listener, a regular file or an inconclusive probe makes the bridge exit
  • socket unlinked on SIGINT/SIGTERM/exit, only while it is still the bridge's own inode

resources/cli/bridge-unix.js is added to the checked-in CLI copies (npm run build:main) and to electron-builder.json, so an installed build does not fail with MODULE_NOT_FOUND.

Test plan

  • Unit tests: rules table in tests/unit/bridge-unix.test.ts, wsl-network.test.ts.
  • Automated end to end in wmux-bridge-transport.test.ts: real socket with a stand-in pipe, stock wmux ping, 0600 mode, SIGTERM cleanup, stale socket after SIGKILL, live listener, regular file, replaced socket, each refusal.
  • Also tested end to end by the author in a real container setup: a container reaching wmux through the bind-mounted socket.

🤖 Generated with Claude Code

stlindenau and others added 2 commits November 26, 2026 14:20
`wmux bridge --wsl` lets a container reach wmux by listening on 0.0.0.0 inside
the distro, and refuses to do that unless `wslinfo --networking-mode` says
`nat`. On managed networks that require `networkingMode=virtioproxy` (called
`consomme` in the WSL docs) the answer is neither `nat` nor `mirrored`, so the
bridge exits with "could not determine this distro's networking mode" and the
container gets no wmux. Binding the Docker bridge address with `--host` is not
a way around it either: in WSL 3.0.5 under `consomme`, bind() to an explicit
port on an address only the distro has fails with EINVAL (microsoft/WSL#42223,
fixed by microsoft/WSL#42230). And what a 0.0.0.0 listener exposes under
`consomme` is not documented, so picking it would be a guess.

`wmux bridge --unix <path>` is the same bridge without an address. It listens
on a Unix socket on the distro's own filesystem; the container gets the
socket's directory bind-mounted and sets WMUX_PIPE=<path in the container> and
WMUX_PIPE_TOKEN. The clients need no change: connectTransport and wmux-hook.js
already dial a Unix socket when WMUX_PIPE starts with "/". No networking mode is
read, so none can make the answer unknown.

This is not the cross-boundary Unix socket that docs/DEVCONTAINER.md says was
tried first. That was a socket on the Windows side, and 9P does not forward
AF_UNIX. Here the socket is created by a process in the distro and used by a
container on the same kernel; a path on a 9P mount (/mnt/<drive>) is refused.

The rules live in a pure module (bridge-unix.ts) so they run on any platform:

* not combinable with --host, --wsl or --port, each of which describes a TCP
  listener;
* an absolute path of at most 107 bytes, not the pipe the bridge relays to;
* the parent directory exists and is not group- or world-writable, sticky bit
  or not, because a socket's own mode does not stop another user replacing it;
* the socket is created under umask 077 and chmod 0600;
* a socket nobody listens on (connect gets ECONNREFUSED) is replaced, which is
  what SIGKILL or a WSL shutdown leaves behind; a live listener, a regular file
  or a probe that proves nothing makes the bridge exit instead;
* the socket is unlinked on SIGINT, SIGTERM and exit, but only while it is
  still the bridge's own inode.

resources/cli/bridge-unix.js is added to the checked-in CLI copies (regenerated
with `npm run build:main`) and to electron-builder.json, which is what keeps a
new CLI module from failing with MODULE_NOT_FOUND in an installed build.

Tests: the rules as a table; and end to end against the compiled CLI, through a
real socket with a stand-in pipe: the stock `wmux ping` with WMUX_PIPE and
WMUX_PIPE_TOKEN, the 0600 mode, SIGTERM cleanup, a stale socket after SIGKILL, a
live listener, a regular file, a replaced socket, and each refusal.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
`wslinfo --networking-mode` prints `consomme` on a host running that mode (the
WSL docs say it used to be called `virtioproxy`, and `.wslconfig` files still
spell it that way). parseNetworkingMode only knew `nat` and `mirrored`, so it
answered "unknown" and `--wsl` refused with "could not determine this distro's
networking mode ... needs WSL 2.0.5 or newer", which sends the reader to check
the WSL version when the version is fine.

The mode is now recognised, and `--wsl` refuses it by name: what a 0.0.0.0
listener exposes to the Windows host and its networks is not documented for
consomme, so it is not treated as NAT, and the message says so and points at
`--unix <path>` (no address at all) or `--host <addr>`. An explicit `--host`
under consomme is still honoured, with a notice that the reach is undocumented
instead of the generic "beyond localhost" one. Nothing is added to the set of
modes that bind 0.0.0.0 on its own.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@amirlehmam
amirlehmam merged commit d294b6c into amirlehmam:master Nov 27, 2026
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.

2 participants

0