volta icon indicating copy to clipboard operation
volta copied to clipboard

Volta Installed node is spawning extra child process

Open ianchudson-caribou opened this issue 1 year ago • 1 comments

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.

ianchudson-caribou avatar Nov 24 '24 19:11 ianchudson-caribou

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?

esamattirs avatar Feb 17 '25 12:02 esamattirs