You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

应用故障时如何自动重启Heroku Dynos?Heroku如何对标K8s探针机制?

How Heroku Handles App Failures and Automatic Dyno Restarts

Great question! Let's break down how Heroku approaches app fault recovery compared to Kubernetes's liveness/readiness probes, and how you can set up automatic restarts for your Dynos.

Default Crash Recovery Behavior

First off, Heroku has a built-in safety net for crashed Dynos. If your app's main process exits with a non-zero status code (like when a web app crashes due to an unhandled exception, or runs out of memory), Heroku's dyno manager will automatically attempt to restart the Dyno immediately.

This is a passive check—Heroku doesn't actively ping your app like Kubernetes does with probes; it just monitors whether your process is running. By default, it will keep retrying restarts (with a small backoff interval for repeated failures) to get your app back up.

Implementing Probe-Like Health Checks (For Active Monitoring)

If you want something closer to Kubernetes's active liveness probes—where the platform checks your app's internal health (not just if the process is running)—Heroku offers a Health Checks feature that you can configure manually. Here's how to set it up:

  • First, add a health check endpoint to your app (e.g., /health). This endpoint should return a 200 OK status code when your app is fully functional, and a 5xx status code if it's in an unhealthy state (like unable to connect to a database, or stuck in a deadlock).
  • Next, configure the health check via Heroku CLI:
    heroku health:add http://<your-app-domain>/health --interval=30 --timeout=5 --failure-threshold=3
    
    This tells Heroku to ping your /health endpoint every 30 seconds, wait 5 seconds for a response, and restart the Dyno if it gets 3 consecutive failures.
  • You can also adjust these settings or manage health checks directly from the Heroku Dashboard under your app's "Settings" tab.

Other Ways to Trigger Automatic Restarts

If you need more flexibility, here are a couple of additional methods:

  • Process Exit Codes: Ensure your app exits with a non-zero code whenever it encounters an unrecoverable error. Heroku will pick up on this and restart the Dyno automatically—no extra configuration needed.
  • Scheduler Add-on: Use the Heroku Scheduler to run a custom script at regular intervals. The script can check your app's health (e.g., by hitting your /health endpoint) and run heroku restart if it detects a failure. Note that this is a periodic check, not real-time like Health Checks.
  • Third-Party Monitoring Tools: Services like New Relic or Datadog can monitor your app's performance and health. You can set up alerts that trigger a Dyno restart via the Heroku API when specific failure conditions are met.

Key Difference from Kubernetes

The biggest contrast is that Kubernetes relies on active, configurable probes to proactively assess app health and take action (restart, mark as unready). Heroku's default behavior is passive (only reacts when the process dies), but you can replicate the proactive probe behavior using Heroku's Health Checks feature.

内容的提问来源于stack exchange,提问作者Andy Verbunt

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 11:52:55