sveltejs / sveltejs/kit

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

Open
#16,230 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

pkg:adapter-node
Dominant language
JavaScript
Stars
20.8k
Forks
2.3k
Avg merge
1d 16h
Merged PRs (30d)
156

Description

Describe the bug

https://github.com/sveltejs/kit/pull/15449 (released in @sveltejs/adapter-node@5.5.7) 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).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with files/index.js and reproduce the issue using adapter-node 5.5.7, a shared SOCKET_PATH, and PM2 or Node cluster mode. Observe whether the live socket is removed during worker startup; done means the socket path remains available for the reverse proxy while stale-socket cleanup still behaves as intended.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nginx, nodejs
Domain
backend, devops, networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.