We are running NodeJS server on Heroku. we want to know whether heroku will restart the application if application crashes. Also will there any different behavior between free version and paid version?
2 Answers
It will. For several times, and then "cool off" for ten minutes and try again. From the docs:
Heroku’s dyno restart policy is to try to restart crashed dynos by spawning new dynos once every ten minutes. This means that if you push bad code that prevents your app from booting, your app dynos will be started once, then restarted, then get a cool-off of ten minutes. In the normal case of a long-running web or worker process getting an occasional crash, the dyno will be restarted instantly without any intervention on your part. If your dyno crashes twice in a row, it will stay down for ten minutes before the system retries.
The docs: https://devcenter.heroku.com/articles/dynos#automatic-dyno-restarts
EDIT Regarding free dynos: the restart behavior is the same. However, there is something called "Dyno Idling" which happens only in free dynos. Basically it means that if your dyno does not receive any request for 1 hour it will "go to sleep", and the next request will "wake it up", which will cause that next request to be slightly delayed. This happens only when you have 1 free web
dyno for your app.
To circumvent that, either have 2 dynos (and then none of them will idle, but you will be paying for one), or have "something" poll your web dyno every (say) 30 minutes. Like pingdom, say.
The docs: https://devcenter.heroku.com/articles/dynos#automatic-dyno-restarts

- 51,456
- 28
- 233
- 198

- 13,460
- 5
- 45
- 54
-
1You mean, it will restart the server instantly. Does it supported in free dyno? because our app does not restarted. I do not understand twice in a row. Is there any specific time of twice in a row? – Fizer Khan Oct 09 '13 at 07:39
-
It's also for the free plan, yes. Twice means it will restart once, and if it still fails then it will wait 10 minutes before restarting again. I will edit my answer to reflect some more info re the free tier. – Nitzan Shaked Oct 09 '13 at 07:48
-
You said, it will go idle if no request for 5 minutes. It is not 5 minutes, it is 1 hours. Regarding free plan restart feature, it does not work for us. Are you sure? – Fizer Khan Oct 09 '13 at 08:27
-
I have posted my heroku logs. http://pastebin.com/bhfyct1L Here server crashes due to mongo db connect issue. Then all request returns time out error. Exactly after 1 hour, sever goes idle. – Fizer Khan Oct 09 '13 at 08:42
-
2Correct re the 5m/1h. I will edit my answer. From the logs, though, it does *not* look as if your process exited after the failure to connect. It seems like you have some kind of code in `uncaughtException` which prevents your process from exiting. That is why it was not restarted by Heroku. – Nitzan Shaked Oct 09 '13 at 08:57
-
one of the best ever answers! – Ehsan Jun 13 '18 at 11:40
Fast-forward to 2022, Go to your app on the Heroku portal
Click on "More" dropdown
Select "Restart all dynos"

- 910
- 1
- 10
- 20