How to pass SIGINT through `npm start` with heroku buildpack?

I have builder = "heroku/buildpacks:20" for a next.js app. The startup logs look like this:

Preparing to run: `/cnb/process/web` as heroku
2022/09/15 05:25:04 listening on [fdaa:0:7524:a7b:9ada:1bfd:ac14:2]:22 (DNS: [fdaa::3]:53)
> user_interface@0.1.0 start
> next start

and then on shutdown

runner[1bfdac14] ord [info]Shutting down virtual machine
app[1bfdac14] ord [info]Sending signal SIGINT to main child process w/ PID 516

This is ps -ef

heroku     516     1 10 05:41 ?        00:00:00 npm start
heroku     536   516  0 05:41 ?        00:00:00 sh -c -- next start
heroku     537   536 27 05:41 ?        00:00:01 node /workspace/node_modules/.bin/next start

If I ssh in and kill -2 537 , I get the expected db connection closing behavior. However fly restart/deploy does not get a SIGINT to my process and connections are leaked. Is there a way to tell heroku/npm to pass signals? Should I just write my own dockerfile instead of using a buildpack and set the entrypoint properly?

I would’ve expected signals to be passed down from npm start. But looking at an old issue, I don’t think that’s ever been fixed.

I’m not sure if it’s possible, but you might be able to override the command via your fly.toml:

cmd = ["node", "/workspace/node_modules/.bin/next", "start"]

If this still fails, you might have to override the entire execution:

exec = ["node", "/workspace/node_modules/.bin/next", "start"]
1 Like

that seems like it would work; I ended up just switching to a dockerfile