Summary
With --listen-socket=fd://3, the Rust implementation adopts fd 3 via from_raw_fd without verifying it is actually a listening AF_UNIX socket. Go's net.FileListener (go/main.go:78) rejects non-socket fds; Rust only surfaces the problem later as io::Error from set_nonblocking/accept (mitigated by the accept-error backoff added in #27 — no busy loop, but also no clear early failure).
Neither implementation checks the LISTEN_PID/LISTEN_FDS environment variables from the sd_listen_fds convention, so this is parity-plus hardening.
Affected implementation(s)
Expected behavior
--listen-socket=fd://3 with an fd that is not a listening AF_UNIX socket should fail fast at startup with a clear error, not degrade into accept errors at runtime.
Suggested fix
Before adopting the fd:
fstat and check S_IFSOCK
getsockopt(SOL_SOCKET, SO_ACCEPTCONN) to confirm it is listening
- Optionally validate
LISTEN_PID == getpid() and LISTEN_FDS >= 1 per the systemd convention (would also make sense in Go for parity)
Also worth a subprocess-based test that dup2s a real listener onto fd 3 and exercises the fd://3 dispatch path end-to-end (currently only the fd-wrapping helper is unit-tested).
Context
Split out from the review follow-ups on PR #27. Related: #25, #28.
Summary
With
--listen-socket=fd://3, the Rust implementation adopts fd 3 viafrom_raw_fdwithout verifying it is actually a listening AF_UNIX socket. Go'snet.FileListener(go/main.go:78) rejects non-socket fds; Rust only surfaces the problem later asio::Errorfromset_nonblocking/accept(mitigated by the accept-error backoff added in #27 — no busy loop, but also no clear early failure).Neither implementation checks the
LISTEN_PID/LISTEN_FDSenvironment variables from thesd_listen_fdsconvention, so this is parity-plus hardening.Affected implementation(s)
net.FileListener; also skipsLISTEN_FDSenv check)Expected behavior
--listen-socket=fd://3with an fd that is not a listening AF_UNIX socket should fail fast at startup with a clear error, not degrade into accept errors at runtime.Suggested fix
Before adopting the fd:
fstatand checkS_IFSOCKgetsockopt(SOL_SOCKET, SO_ACCEPTCONN)to confirm it is listeningLISTEN_PID == getpid()andLISTEN_FDS >= 1per the systemd convention (would also make sense in Go for parity)Also worth a subprocess-based test that
dup2s a real listener onto fd 3 and exercises thefd://3dispatch path end-to-end (currently only the fd-wrapping helper is unit-tested).Context
Split out from the review follow-ups on PR #27. Related: #25, #28.