Skip to content

fix(adapter-node): skip socket cleanup for cluster workers#16241

Open
tsushanth wants to merge 1 commit into
sveltejs:mainfrom
tsushanth:fix/16230-adapter-node-cluster-socket-deletion
Open

fix(adapter-node): skip socket cleanup for cluster workers#16241
tsushanth wants to merge 1 commit into
sveltejs:mainfrom
tsushanth:fix/16230-adapter-node-cluster-socket-deletion

Conversation

@tsushanth

Copy link
Copy Markdown

Fixes #16230.

Root cause

The stale-socket cleanup added in #15449 (released in adapter-node 5.5.7) unconditionally runs on every process startup:

if (fs.statSync(path).size === 0) {
  await rm(path);
}

The size === 0 heuristic is meant to detect a stale socket left over from an unclean shutdown, but a live unix domain socket also reports size = 0. In Node cluster / PM2 cluster mode:

  1. The primary process binds and creates the socket file.
  2. Each worker process inherits the primary's listening handle (no bind() of its own), runs the same startup code, finds size === 0, and deletes the live socket file.
  3. Workers appear healthy (they share the in-kernel listening state), but the socket path is gone from disk — the reverse proxy (e.g. nginx proxy_pass unix:…) can no longer connect. No error, no restart, silent regression.

Fix

Import node:cluster and skip the rm() call when the current process is a cluster worker. Workers inherit the socket handle from the primary and must never manage the socket file. The primary (or any single-process deployment) retains the existing cleanup behaviour unchanged.

cluster.isWorker is false in non-cluster processes, so this change is a no-op for single-process deployments.

The stale-socket cleanup added in sveltejs#15449 runs on every process start, but
in Node cluster / PM2 cluster mode all worker processes share the primary's
socket handle. A live unix socket also reports size = 0, so each worker
deletes the socket file the primary just created. After the deletion the
reverse proxy can no longer connect — the server appears healthy (workers
share the in-kernel listening state) but the socket path is gone from disk.

Fix: skip the rm() call when process is a cluster worker. Workers never
bind the socket themselves, so they must never clean it up.
@pkg-svelte-dev

pkg-svelte-dev Bot commented Jul 5, 2026

Copy link
Copy Markdown

Install the latest version of @sveltejs/kit from 9fd278c:

pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/9fd278c9ccade1944441c961fcc6f855891b15f8

Open in pkg.svelte.dev: https://pkg.svelte.dev/repos/kit/pr/16241

Note

This PR is from a fork. A maintainer must approve approve each commit before it can be built and installed.

@changeset-bot

changeset-bot Bot commented Jul 5, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 9fd278c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants