Repository navigation
silkd: accept vsock connections close-on-exec atomically - #540
Conversation
vsock 0.5 sets FD_CLOEXEC with fcntl after accept(2), so an exec spawned on another runtime thread in that window inherits the new control connection. On a 4-vCPU guest 0.1-0.43% of root execs held another live silkd connection; accept4 with SOCK_CLOEXEC closes the window.
Hardware verification: passSetup. Two identical 4-vCPU pools with tun on, one claim per arm. Both guest images are stock
Method. Each pass ran N execs, each over a fresh vsock connection. Every child listed its own socket fds and reported Leaks (leaked sockets / execs; passes in run order, ABBA):
Control path on B, once each, all OK:
Exec throughput (execs/s, median of the passes): mixed, and not attributable to the change.
|
vsock_accept checks for a pending signal before it returns EAGAIN, so a nonblocking accept4 returns EINTR when a SIGCHLD from an exited exec lands on the accepting thread. tokio-vsock retried it at once; the new loop took the 50 ms error backoff on every such accept.
|
Follow-up e4d877c. When a signal is pending, |
Hardware rerun on e4d877c (EINTR retry): passSame host and stack as the earlier runs. The two arms were swapped between two 4-vCPU pools in both orders, ABBA ×4 per order, 3000 root execs @64 per pass. In-guest silkd sha matched each arm.
|
vsock0.5.4 callsaccept(2)and only afterwards setsFD_CLOEXECwithfcntl. An exec spawned on another tokio worker during that window inherits the new silkd control connection, and the child can read that client's requests and write frames to the host.Change
sysutil::vsock_acceptcallsaccept4(SOCK_CLOEXEC | SOCK_NONBLOCK)and returns the fd together with the peer cid.vsock::servebinds the listener throughvsock, which already creates it withSOCK_CLOEXEC, and registers it withAsyncFd. It accepts throughasync_io, so WouldBlock and readiness are handled by tokio.Evidence (hardware, base e38c762)
Gates (Linux arm64 container, rust 1.99.1)
cargo fmt --check: clean.cargo clippy --all-targets -- -D warnings: clean.cargo test: all pass.