A crash loop is a failure pattern in which a service or process starts, fails shortly afterward and is restarted automatically, over and over, without ever reaching a stable running state. In the management of services & processes on servers, it appears whenever a restart policy keeps reviving a process whose underlying fault has not been fixed, such as a missing configuration file, an unreachable dependency or a port that is already in use.
In Kubernetes the condition is reported as CrashLoopBackOff, which means that the kubelet is waiting before the next restart attempt. The same pattern exists under systemd, Supervisord, PM2 and Docker restart policies. A crash loop is a symptom, not a root cause: the supervisor behaves correctly, while the process repeatedly exits for a reason that must be found in its logs or exit code.
How a crash loop develops
Every crash loop combines two ingredients: a process that exits abnormally and a supervisor configured to restart it. Supervisors such as systemd, Docker or the kubelet exist to keep services available, so they interpret an exit as a transient failure and try again. When the fault is deterministic, every attempt fails the same way and the cycle repeats.
To avoid hammering the system, most supervisors apply exponential backoff between attempts. Kubernetes starts with a delay of about 10 seconds and doubles it up to five minutes, resetting the timer after a container runs successfully for ten minutes. systemd instead counts failures and stops restarting once StartLimitBurst is reached within StartLimitIntervalSec, leaving the unit in a failed state.
The table below shows how common supervisors express the same pattern.
| Supervisor | Restart setting | Visible symptom |
|---|---|---|
| Kubernetes kubelet | restartPolicy: Always | Pod status CrashLoopBackOff, rising restart count |
| systemd | Restart=on-failure | Unit enters failed after the start limit is hit |
| Docker | –restart unless-stopped | Container shows Restarting with a short uptime |
| Supervisord | autorestart=true | Program reaches FATAL after startretries |
| PM2 | autorestart with max_restarts | Process status errored, high restart counter |
Typical causes of a crash loop
The causes fall into a small number of families, and the exit code is usually the fastest clue. An exit code of 1 points to an application error, 137 indicates a SIGKILL, often from the out-of-memory killer, and 139 signals a segmentation fault.
| Cause | Typical evidence | Usual fix |
|---|---|---|
| Invalid configuration | Parse error in the first log lines | Correct the file or environment variable |
| Missing secret or file | File not found, permission denied | Mount the volume or fix ownership |
| Unavailable dependency | Connection refused to database or queue | Add retries or start ordering |
| Port already bound | Address already in use | Stop the conflicting process or change the port |
| Memory exhaustion | Exit code 137, OOMKilled reason | Raise the limit or reduce usage |
| Failing liveness probe | Killed while the application still starts | Lengthen the probe delay or add a startup probe |
A subtle variant is the probe-induced crash loop. The application itself is healthy but slow to initialize, and an aggressive liveness probe kills it before it finishes booting. Each restart begins the slow startup again, so the container never survives long enough to pass the probe.
Crash loop compared with related failure states
A crash loop is easy to confuse with other unhealthy states, yet each one calls for a different diagnostic path. The comparison below separates them by what the process is actually doing.
| State | Process behavior | Supervisor reaction |
|---|---|---|
| Crash loop | Exits repeatedly soon after start | Restarts with backoff or gives up |
| Hung process | Keeps running but stops responding | Nothing, unless a watchdog or probe acts |
| Restart storm | Many services restart together | Shared dependency overwhelmed by reconnects |
| Graceful restart | Planned stop and start | Intended, no error condition |
| Image pull failure | Never starts at all | Kubernetes reports ImagePullBackOff |
The distinction from a hung process matters most. A crash loop is noisy and visible in restart counters, whereas a hung process can stay silent for hours. A watchdog timer or liveness probe can turn a hang into a restart, which occasionally converts one problem into the other.
Diagnosing and stopping a crash loop
Effective diagnosis starts with the logs of the previous, failed instance, because the current instance may not have produced any output yet. In Kubernetes this means kubectl logs --previous, while systemd keeps earlier runs in the journal, readable with journalctl -u followed by the unit name.
- Read the exit code and termination reason with kubectl describe pod, systemctl status or docker inspect.
- Inspect the last log lines of the failed run, not only the newest container.
- Reproduce interactively by starting the image or binary with a shell to test configuration and connectivity.
- Check recent changes such as a new image tag, a rotated secret or an edited configuration map.
- Pause the restarts by scaling to zero or stopping the unit while the fix is prepared.
Prevention relies on fail-fast validation and sensible policies. A service should check its configuration at startup and exit with a clear message, dependencies should be retried inside the application rather than through repeated process restarts, and startup probes should protect slow initializations from premature liveness checks.
Operational risks of an unattended crash loop
An unnoticed crash loop consumes resources and hides outages. Each restart costs CPU time, fills log storage, may open new database connections and can trigger repeated cache warm-ups that slow other services on the same host.
- Masked downtime: an orchestrator may report the deployment as present while no replica serves traffic.
- Log flooding that rotates away the first, most informative error message.
- Cascading load on a database or message broker when every attempt reconnects at once.
- Failed rollouts that stall when new replicas never become ready.
For that reason, alerting on restart counts is a standard practice in process monitoring. A rule that fires when a container restarts more than three times in fifteen minutes catches most loops long before users report errors.
A plain-language summary
Servers often run programs under a helper that restarts them automatically if they stop. That is useful when a program stumbles once. A crash loop happens when the program fails every single time it starts, so the helper keeps restarting it and it keeps falling over.
It resembles a car that stalls the moment the engine starts. Turning the key again and again will not help, because something is wrong underneath. The fix is to find out why it stalls, not to keep turning the key.
An example from practice
A platform team deploys a new version of a payment API to a Kubernetes cluster with three replicas. Within two minutes, all new pods show CrashLoopBackOff with restart counts of four and rising, and the rollout stops because no new replica becomes ready.
Running kubectl logs --previous reveals that the service exits with code 1 after printing “missing required variable DB_PASSWORD”. The new release renamed the expected variable, but the deployment manifest still provides the old name. The engineer corrects the environment mapping and applies the manifest again.
The outcome: the pods start on the first attempt, the rollout completes in under three minutes, and the old replicas, which the rolling update had kept running, served traffic throughout without customer impact. The team adds a configuration validation step to its pipeline to catch similar mismatches before deployment.