Volta Installed node is spawning extra child process
When I use volta in a container to install node, it's spawning an extra child process which causes shutdown to behave incorrectly.
node index.js is resulting in a process with a child process also called node index.js
This means when SIGTERM is sent to PID Parent, nothing happens, the server is all running on PID Child.
The exact same code, using node's image results in 1 process and behaves as expected.
A little more info/guessing. It would appear that signals sent to the node shim are not being sent to the actual node process. I would assume this is unexpected/bug behavior as it prevents correct shutdown/response.
Here's a simple script to reproduce
echo "initial pid $$"
exec node -e 'console.log(`Node pid is ${process.pid}`)'
Since the script is using exec it replaces itself with the node.js process and the pids are the same. But this is not happening when using Volta. We have a testing tool that starts node.js processes using wrapper scripts like this and then kills them using the script's pid. Unfortunately it does not work when using Volta. It just kills the parent process leaving the node.js process running.
Another way to debug this is with pstree. When starting without the exec the process tree looks like this
❯ pstree 74362
-+= 74362 esamatti /bin/sh ./start.sh
\--- 74363 esamatti node server.mjs
with Volta it looks like this
❯ pstree 74477
-+= 74477 esamatti /bin/sh ./start.sh
\-+- 74478 esamatti node server.mjs
\--- 74479 esamatti node server.mjs
So the Volta binary might be starting the node.js process as a child process when it should be using exec too?
I reproduced the shutdown problem with Volta 2.0.2 on Linux x86_64. After cancelling execFile() and waiting for its close event, an immediate attempt to bind the same TCP port still returns EADDRINUSE. The child opens its listener before cancellation and closes it after 2.5 seconds so the reproduction cleans itself up.
Save this as listener and run chmod +x listener.
#!/usr/bin/env node
const server = require('node:net').createServer().listen(0, '127.0.0.1', () => {
console.log(server.address().port);
});
setTimeout(() => server.close(), 2500);
Save this as probe.mjs.
import { execFile } from 'node:child_process';
import { once } from 'node:events';
import { createServer } from 'node:net';
import { promisify } from 'node:util';
const controller = new AbortController();
const child = promisify(execFile)('./listener', [], {
signal: controller.signal,
killSignal: 'SIGTERM',
});
const result = child.catch((error) => error.code);
const closed = new Promise((resolve) => {
child.child.once('close', (code, signal) => resolve({ code, signal }));
});
const [chunk] = await once(child.child.stdout, 'data');
const port = Number(String(chunk).trim());
controller.abort();
const abortError = await result;
const close = await closed;
const server = createServer();
const bind = await new Promise((resolve) => {
server.once('error', (error) => resolve(error.code));
server.listen(port, '127.0.0.1', () => server.close(() => resolve('OK')));
});
console.log({ abortError, close, bind });
Run the parent using the same Node binary in both cases. Change only which node the child's shebang finds.
real_node="$(volta which node)"
shim_dir="${VOLTA_HOME:-$HOME/.volta}/bin"
PATH="$shim_dir:/usr/bin:/bin" "$real_node" probe.mjs
PATH="$(dirname "$real_node"):/usr/bin:/bin" "$real_node" probe.mjs
With Node 26.13.1 as the parent, the shim case returned EADDRINUSE in 5 of 5 runs. The direct case returned OK in 5 of 5 runs. I repeated the comparison with Bun 1.4.4 as the parent and got the same results. Both parents reported ABORT_ERR and close with SIGTERM. The TCP listener only survived in the shim case.