App not receiving SIGINT

I am running a NodeJS http express server on my fly machine. Every time Fly sends SIGINT, it does not seem to make it to my app. I am trying to ‘catch’ the SIGINT in my app.js like this. However, nothing gets printed and I get [warn]Virtual machine exited abruptly

process.on('SIGINT', () => {
	console.log('Received SIGINT, shutting down gracefully...');
	process.exit(0);
});

Any idea why this may be? Here is my repo which also contains the fly.toml and relevant www and app.js files. My app runs with NODE_ENV=production node ./bin/www

I would really appreciate some help with this :blush:

CMD [ "npm", "run", "start" ]

Try running node server.js directly. The signal might not be properly propagating through npm wrapper.

1 Like

Line 29 in your Dockerfile is the cause. Switch from npm start to the CMD ["node", "./bin/www"] and that should do it. I believe NODE_ENV is already set in the machine given that it’s set in the Dockerfile

1 Like

In addition to the two comments above me, the following may help: [BUG] npm not handling process signals · Issue #6684 · npm/cli · GitHub

1 Like

I updated line 39 to now be CMD ["node", "./bin/www"] which completely fixed my issue! Thank you so much, I’ve been really struggling trying to get this working. I appreciate your help tremendously. Not sure why this dockerfile was incorrect… It was auto-generated with fly launch. I did try creating a new test app using fly launch again and it looks like it generated a dockerFile that was using the format you suggested. I guess there’s been an update from Fly on how dockerFiles get generated…

I do have one more small issue now. I see it even with a very simple helloWorld express JS app. I see this error when shutting machine down: WARN could not unmount /rootfs: EINVAL: Invalid argument

Any idea what may be causing that or is it an ongoing Fly issue I should ignore?

That’s a benign warn log. Fly should mute it to avoid confusion.

3 Likes

ok, great, in that case I will ignore it. Thank you!

That’s the default generated by flyctl. As with any automated generation tool, cross check that what it gives you what you really want. They’re good at providing defaults that most apps need but may easily get out of date. And you can switch to Node 22 for your base image to utilise more features and performance improvements