Maëlig
Maëlig

Reputation: 409

Heroku Node.js app keeps crashing and restarting

Update : I made a minimal reproducible example with a simple console.log() as my Node.js script, and I still have the same issue (app "crashes" after execution and is restarted after a seemingly random interval by Heroku), so I'm guessing that there must be something I'm fundamentally misunderstanding about how Heroku works...

I'm running a few different Node.js apps on Heroku, using the standard heroku/nodejs buildpack. I'm getting the same problem on all of them, which is that the script executes fine, but then after it's done it seems that Heroku considers the app crashed and tries to relaunch it, which results in the script being executed too many times. The logs don't seem to help much :

Jul 21 12:09:01 markov-lyrics app/worker.1 successfully posted
Jul 21 12:09:01 markov-lyrics heroku/worker.1 Process exited with status 0
Jul 21 12:09:01 markov-lyrics heroku/worker.1 State changed from starting to crashed
Jul 21 12:33:56 markov-lyrics heroku/worker.1 State changed from crashed to starting
Jul 21 12:33:59 markov-lyrics heroku/worker.1 Starting process with command `npm start`

The first line in this output is a console.log that I put at the end of my script to check if everything went fine, the rest is logged by Heroku itself. I should point out that there is no web server launched as part of the script (not needed as I'm just making some API calls). I've tried to run it using the worker free dyno disabling the web dyno, and vice-versa but this doesn't seem to have an impact. The script executes and terminates normally when I run it locally.

My package.json file includes this :

"scripts": {
    "start": "node index.js"
  },

I'm out of ideas as to what might be causing this and would appreciate the help !

Upvotes: 2

Views: 372

Answers (1)

Maëlig
Maëlig

Reputation: 409

It was actually simpler than I thought, but the concept / types of dynos confused me. Scripts that are meant to execute and finish should not actually use any web or worker dynos, just the scheduler. The scheduler will run off of its own one-off dyno.

Upvotes: 3

Related Questions