{"record":{"id":"b4e80f108794cf0f","repo":"sveltejs/kit","slug":"received-listen-pid-listen-pid-but-current-proc","errorCode":null,"errorMessage":"received LISTEN_PID ${listen_pid} but current process id is ${process.pid}","messagePattern":"received LISTEN_PID (.+?) but current process id is (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/adapter-node/src/index.js","lineNumber":21,"sourceCode":"import process from 'node:process';\nimport { handler } from './handler.js';\nimport { env, timeout_env } from './env.js';\nimport { rm } from 'node:fs/promises';\nimport { format_listening_address } from './utils.js';\n\nexport const path = env('SOCKET_PATH', false);\nexport const host = env('HOST', '0.0.0.0');\nexport const port = env('PORT', !path && '3000');\n\nconst shutdown_timeout = parseInt(env('SHUTDOWN_TIMEOUT', '30'));\nconst idle_timeout = parseInt(env('IDLE_TIMEOUT', '0'));\nconst listen_pid = parseInt(env('LISTEN_PID', '0'));\nconst listen_fds = parseInt(env('LISTEN_FDS', '0'));\n// https://www.freedesktop.org/software/systemd/man/latest/sd_listen_fds.html\nconst SD_LISTEN_FDS_START = 3;\n\nif (listen_pid !== 0 && listen_pid !== process.pid) {\n\tthrow new Error(`received LISTEN_PID ${listen_pid} but current process id is ${process.pid}`);\n}\nif (listen_fds > 1) {\n\tthrow new Error(\n\t\t`only one socket is allowed for socket activation, but LISTEN_FDS was set to ${listen_fds}`\n\t);\n}\n\nconst socket_activation = listen_pid === process.pid && listen_fds === 1;\n\nlet requests = 0;\n/** @type {NodeJS.Timeout | void} */\nlet shutdown_timeout_id;\n/** @type {NodeJS.Timeout | void} */\nlet idle_timeout_id;\n\nconst httpServer = http.createServer();\n\nconst keep_alive_timeout = timeout_env('KEEP_ALIVE_TIMEOUT');","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/adapter-node/src/index.js#L3-L39","documentation":"@sveltejs/adapter-node supports systemd socket activation via the sd_listen_fds protocol. When LISTEN_PID is set it must match the PID of the process that actually received the inherited socket file descriptors. If it points at a different process, the fds belong to someone else, so the adapter refuses to start rather than silently grabbing the wrong socket.","triggerScenarios":"LISTEN_PID is set in the environment to a nonzero value that does not equal process.pid at server startup in packages/adapter-node/src/index.js.","commonSituations":"Running the server under a supervisor or wrapper (shell script, daemonizing tool, container init) that received the socket but spawns the node process as a child, so the child inherits LISTEN_PID pointing at the parent PID; manually exporting LISTEN_PID for testing; using systemd socket activation with a forking service Type.","solutions":["Ensure the node process itself is the one systemd/socket-activation hands the socket to — run it as the direct child of the activating supervisor","Unset LISTEN_PID (and LISTEN_FDS) if you are not intentionally using socket activation: `env -u LISTEN_PID -u LISTEN_FDS node build`","If a wrapper script is needed, have it exec the node process (exec node build) so the PID stays the same","Configure systemd with Type=exec/simple so the service PID is the one that gets LISTEN_PID"],"exampleFix":"# before\nLISTEN_PID=1234 ./run.sh   # run.sh spawns node as a child\n# after\nexec node build            # same PID inherits and validates LISTEN_PID","handlingStrategy":"validation","validationCode":"if (process.env.LISTEN_PID && parseInt(process.env.LISTEN_PID) !== process.pid) {\n  delete process.env.LISTEN_PID; // or fail fast with a clear message before starting the server\n}","typeGuard":"const socketActivationValid = (env = process.env) =>\n  !env.LISTEN_PID || parseInt(env.LISTEN_PID, 10) === process.pid;","tryCatchPattern":"try {\n  startServer();\n} catch (err) {\n  if (/LISTEN_PID/.test(err.message)) {\n    console.error('Socket activation PID mismatch — check your supervisor/wrapper.');\n    process.exit(1);\n  }\n  throw err;\n}","preventionTips":["Use `exec` in wrapper scripts so the node process keeps the activated PID","Do not manually export LISTEN_PID/LISTEN_FDS outside real socket activation","Prefer Type=exec/simple systemd services with socket activation","Unset socket-activation vars when running the server locally"],"tags":["node","socket-activation","environment","systemd"],"backgroundTag":"socket-activation-pid-mismatch","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}