kit icon indicating copy to clipboard operation
kit copied to clipboard

adapter-node 5.5.7: "delete existing socket file on startup" (#15449) breaks SOCKET_PATH under Node cluster / PM2 cluster mode

Open enda opened this issue 5 months ago • 0 comments

Describe the bug

https://github.com/sveltejs/kit/pull/15449 (released in @sveltejs/[email protected]) added an unconditional cleanup that deletes the existing socket file on startup:

// files/index.js
if (path) {
      try {
              if (fs.statSync(path).size === 0) {
                      await rm(path);
              }
      } catch {
              // ignore
      }
}
server.listen({ path, host, port }, ...)

The intent (removing a stale socket left over from an unclean shutdown to avoid EADDRINUSE) is reasonable for a single process, but the "is it stale?" heuristic is statSync(path).size === 0 — and a live unix domain socket also reports size 0. So this deletes live sockets too.

This breaks any multi-process deployment that shares a single socket path via the Node cluster module (including PM2 cluster mode):

  1. Worker A boots -> no file -> listen({ path }) -> the cluster primary binds and creates the socket file.
  2. Workers B..N boot -> they run the same top-of-module cleanup -> statSync(path).size === 0 is true for the now-live socket -> rm(path) deletes the socket file the primary just created.
  3. All workers end up online (they share the primary's listening handle, so listen() doesn't error), but there is no socket file on disk -> the reverse proxy (nginx proxy_pass unix:.../node.sock) can no longer connect.

Net effect: the server is listening in-kernel but the socket path is gone, with no error and no restart, very hard to diagnose. Downgrading to 5.5.6 (or any version before #15449) restores correct behavior.

Reproduction

  • adapter-node >= 5.5.7, SOCKET_PATH=/path/node.sock
  • Run under PM2 cluster mode with instances: > 1 (or Node's cluster with several workers on the same socket path)
  • Observe: workers online, 0 restarts, but node.sock is missing from disk.

Logs


System Info

- @sveltejs/adapter-node: 5.5.7 (broken) / 5.5.6 (works)
- Node: 24
- PM2 cluster mode


$ npx envinfo --system --binaries --browsers --npmPackages "{svelte,@sveltejs/*,vite}"
  System:
    OS: Linux 6.12 Debian GNU/Linux 13 (trixie) 13 (trixie)
    CPU: (12) x64 Intel(R) Xeon(R) CPU D-1531 @ 2.20GHz
    Memory: 14.18 GB / 31.25 GB
    Container: Yes
    Shell: 5.2.37 - /bin/bash
  Binaries:
    Node: 24.17.0 - /usr/local/bin/node
    npm: 11.13.0 - /usr/bin/npm

Severity

blocking an upgrade

Additional Information

Silent regression: no log, no crash, no restart: the process looks healthy while being unreachable. Affects a common production topology (SvelteKit + adapter-node + unix socket + PM2/cluster behind nginx).

enda avatar Jul 03 '26 10:07 enda