了解 Heroku 服务器状态143

我想知道 Heroku 服务器的状态,但是找不到任何关于这个主题的文档。

例如:

Process exited with status 143

有人能解释一下这个例子吗? 我在哪里可以找到以后参考的资源?

81198 次浏览

Exit code 143 means that your process was terminated by a SIGTERM. This is generally sent when you do any commands that require your dynos to restart (config:set, restart, scale down...).

It is an idle state when it does not receive any request for a while. When it receives a request it will start again.

Daily restarts is a regularly Heroku dynos lifecycle activity:

Heroku automatic dyno restarts

Restart the dyno, which causes the dyno to receive SIGTERM. use this command

heroku restart worker.1

and then

heroku logs

It is due to the heroku app stopped by dyno. So you have to restrat the app. You can type heroku restart in the terminal. Also heroku restart --app application_name

None of the answers are addressing this. It is definitely not good to be getting "process exited with status 143". It's a sign that your app is not doing things correctly.

Check out this page from the Heroku docs, specifically the sections on restarting and shutdown.


Basically, there are a number of reasons why your dyno may be restarted. Heroku does automatically restart your dyno every 24 hours, (manual restarts and deploys will reset this 24 hour period) but it can also restart your dyno for other reasons.

It's important to understand that it can be terminated at any given time, and your app needs to be designed with this in mind. For example, say you have a worker process that works some queue, popping items from the queue and doing some work on them. Wouldn't it be bad if you popped the items but then the app terminated and you couldn't do the work? Or do you have some lines of code where it might be bad if the app stopped in the middle of their execution?


Heroku does not just yank the power cord on your app; it sends a SIGTERM signal. Heroku also says (in the above link) that it's a bad idea to ignore that signal. If you're getting "process exited with status 143", it means you're not listening for that signal (for python anyway).

If you're not doing anything in your code to listen for this signal, then you're playing a dangerous game (unless it's okay for your app to be terminated at any point in its execution).


For a python app, if you don't tap into the SIGTERM signal, your app is terminated immediately (as soon as Heroku sends that signal), and you get a "process exited with status 143". Not good.

If however, you tap into that signal, then your app gets 30s to gracefully shutdown before it'll be terminated, which is ample time to finish up any work you were doing. To basically stop doing new work, and complete what you're doing if you know it'll take <30s, or put back unfinished work onto a queue, and then exit, or break whatever loop you were in. You should get "process exited with status 0". That's good.

Also, if you did tap into the signal but you don't exit in 30s, then you get an "Error R12 (Exit timeout) -> At least one process failed to exit within 30 seconds of SIGTERM", and the app is terminated with SIGKILL. You get a "process exited with status 137". Also not good.

In the above link (in the shutdown section), they give an example in ruby of how to tap into that signal. And here is an example in python.

When I check the logs:

 heroku[web.1]: Idling
heroku[web.1]: State changed from up to down
heroku[web.1]: Stopping all processes with SIGTERM
heroku[web.1]: Process exited with status 143

It clearly says it's because of Idling, but how can prevent that. When I open the web app with URL, Dyno starts the app again. but in my case I use selenium chrome driver in the background and there is no real user.

so there should be a way to check my URL every N-minutes to prevent it from shutting down

I found a New Relic APM add-ons and also http://kaffeine.herokuapp.com/ to resolve it on this post

https://stackoverflow.com/questions/5480337/easy-way-to-prevent-heroku-idling#:~:text=You%20can%20install%20the%20free,preventing%20the%20dyno%20from%20idling.