code wiki / (root) / nx_fd_hygiene.nx

nx_fd_hygiene.nx

buildroot/runtime/nx_fd_hygiene.nx

1308 B23 linesdepth 2pulls 2 transitivereach 3 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_fd_hygiene.nx -- fd-leak hygiene primitive (2026-07-17). A long-lived supervisor/launcher that forks+execs daemons must not leak INHERITED file descriptors into them: a leaked LISTEN socket keeps its port held, so a redeployed daemon can no longer rebind it. That is exactly what took the mgmt control plane down for ~10 min on 2026-07-17 -- nx_hostctl had inherited mgmt's :18098 listen socket at startup and propagated it to every daemon it forked (children inherit the supervisor's fd table), so a rebuilt mgmt hit EADDRINUSE. nx_fd_scrub_inherited() closes every fd >= 3, preserving stdio (0,1,2). Called ONCE at a supervisor's entry it fixes the whole process tree by construction: a clean supervisor fd table yields clean children. Closing an already-closed fd is a harmless EBADF no-op, so the scrub is safe to run unconditionally. Returns the count of fds that were actually open (closed). license_tier: ORIGINAL

dependencies 1 imports · 2 importers

nx_syscalls.nx nx_fd_hygiene.nx nx_fd_hygiene_gate.nx nx_hostctl.nx

imports: nx_syscalls.nx

imported by: nx_fd_hygiene_gate.nxnx_hostctl.nx

structs

none

consts

13const NX_FD_SCRUB_MAX: i64 = 1024 // POSIX default soft RLIMIT_NOFILE; covers every fd a supervisor could hold

functions

15func nx_fd_scrub_inherited() -> i64
called by 2: maincmd_supervise calls 1: sys_close