Why Flink Jobs Restart: Checkpoint Failures and Recovery
Repeated checkpoint failures can cause a Flink job to fail and restart, but they are not the only reason. Understanding the difference between a failed checkpoint, a failed task, and the configured recovery strategy makes it much easier to diagnose a restart loop.
The key distinction is: a failure triggers recovery only if the restart strategy permits it. If restarting is disabled, or the strategy’s retry budget is exhausted, the job remains failed.
1. When Checkpoint Failures Cause Job Failure
Checkpointing periodically saves operator state and source positions so a streaming job can recover consistently. It must be enabled; Flink does not checkpoint every job automatically.
The setting setTolerableCheckpointFailureNumber(n) controls how many consecutive counted checkpoint failures are tolerated before Flink fails the job. Its corresponding configuration key is execution.checkpointing.tolerable-failed-checkpoints.
For example, with a limit of 3 and checkpoints attempted one at a time:
| Checkpoint outcome | Consecutive counted failures | Result |
|---|---|---|
| First failure | 1 | Tolerated |
| Second failure | 2 | Tolerated |
| Third failure | 3 | Tolerated |
| Fourth failure | 4 | The limit is exceeded; the job fails |
A successfully completed checkpoint resets the consecutive-failure counter. With the documented default of 0, the first counted checkpoint failure can fail the job.
Not Every Failed or Aborted Checkpoint Counts
According to the Flink checkpointing documentation, this tolerance applies to:
- Checkpoint-related
IOExceptions on the JobManager. - Failures during the asynchronous checkpoint phase on TaskManagers.
- Checkpoints that expire because they exceed the checkpoint timeout.
Failures during the synchronous checkpoint phase on a TaskManager can fail the affected task directly, regardless of this tolerance setting. Other checkpoint outcomes, such as a checkpoint being subsumed by another, are ignored by the failure-tolerance mechanism.
This means a failed-checkpoint count in the UI is not, by itself, proof that the tolerance limit caused a restart. Check the failure reason and the JobManager’s exception chain.
Example Checkpoint Configuration
StreamExecutionEnvironment env =
StreamExecutionEnvironment.getExecutionEnvironment();
env.enableCheckpointing(60_000);
env.getCheckpointConfig().setCheckpointTimeout(120_000);
env.getCheckpointConfig().setTolerableCheckpointFailureNumber(3);
These example values enable checkpoints every minute, allow up to two minutes for completion, and tolerate three consecutive counted failures. They are not a universal production recommendation. Configure durable checkpoint storage separately, and confirm the APIs and settings supported by your Flink version.
Increasing the tolerance does not repair checkpointing. If checkpoints keep failing, the last usable recovery point gets older, potentially increasing replay time and recovery work.
2. Other Common Reasons a Flink Job Restarts
A checkpoint error can be a symptom of a wider problem rather than the original cause.
| Failure source | What can happen | What to inspect |
|---|---|---|
| User-code exceptions | An unhandled exception in an operator fails a task. | The earliest relevant exception, operator name, and triggering input. |
| JVM heap exhaustion | An OutOfMemoryError can fail a task or terminate its TaskManager. | Heap usage, state growth, allocations, and memory leaks. |
| Long GC pauses | A worker can become unresponsive and miss heartbeats. | GC logs, pause durations, and heartbeat-loss messages. |
| Network-buffer exhaustion | Shuffle or network operations fail because buffers are unavailable. | Network-memory configuration, parallelism, and shuffle topology. |
| Container or worker loss | Kubernetes, YARN, or the operating system removes a TaskManager. | Container termination reasons, exit codes, evictions, and worker logs. |
| Network connectivity loss | The JobManager loses contact with a worker. | Heartbeat timeouts and infrastructure or network events. |
For example, an unhandled parsing error or NullPointerException in processElement can fail a task. A database lookup failure can do the same if it propagates out of the operator; not every unsuccessful lookup necessarily causes a restart.
Memory failures also require distinguishing Java heap usage from total process memory. Large state in HashMapStateBackend can put pressure on the heap. RocksDB, direct buffers, and other native allocations can consume memory outside it. A container may be OOMKilled even when the Java heap is below its maximum.
Backpressure can delay checkpoint barriers or checkpoint completion until a timeout occurs. However, backpressure alone is not automatically a task failure; investigate the slow operator, external dependency, or storage bottleneck behind it.
3. Restart Strategy Versus Failover Strategy
Flink uses two related but different decisions during recovery:
| Strategy | Question it answers |
|---|---|
| Restart strategy | May recovery be retried, and how long should Flink wait? |
| Failover strategy | Which tasks need to restart to recover consistently? |
Common restart strategies include:
- Fixed delay: Retry a configured number of times, waiting a fixed duration between attempts.
- Failure rate: Allow recovery while failures remain within a configured rate limit over a time interval.
- Exponential delay: Increase the delay between retries, subject to configured limits.
- No restart: Leave the job failed instead of retrying.
For example, these configuration entries select up to three fixed-delay restart attempts, with ten seconds between attempts:
restart-strategy.type: fixed-delay
restart-strategy.fixed-delay.attempts: 3
restart-strategy.fixed-delay.delay: 10 s
Apply these entries through the configuration mechanism used by your deployment. A job-specific restart strategy can override the cluster default. Defaults can also depend on the Flink release and whether checkpointing is enabled, so do not assume every job uses fixed-delay recovery.
Does Flink Always Restart Every Subtask?
No. Exceeding the checkpoint-failure tolerance can trigger a job-wide failure. For task failures, Flink’s failover strategy may restart the entire job or only the affected pipelined regions.
It is therefore more accurate to say that Flink cancels and restarts the tasks selected for recovery, rather than that every failure always cancels every running subtask.
4. Task Restarts Are Not the Same as Worker Restarts
The word restart can describe recovery at different layers. Restarting a Flink task is not necessarily the same operation as restarting a TaskManager JVM, a container, or a Kubernetes pod.
When the TaskManager Process Is Killed
If an out-of-memory kill or another fatal event terminates the TaskManager JVM, Flink cannot restart tasks inside that dead process. Recovery requires scheduling those tasks on a healthy worker, which may be an existing TaskManager or a newly started one.
When additional workers are needed, a typical recovery sequence is:
- Detect the lost worker. The JobManager and resource-management components observe a disconnected worker or a heartbeat timeout.
- Obtain replacement capacity. In resource-managed deployments such as native Kubernetes or YARN, Flink’s ResourceManager can request new workers through the resource-provider integration. In standalone deployments, worker replacement is handled by the surrounding infrastructure, such as a Kubernetes Deployment controller.
- Start a fresh TaskManager JVM. A replacement container or worker starts a new process. It does not continue execution inside the terminated JVM.
- Register and allocate slots. The new TaskManager registers with the ResourceManager. Flink coordinates slot allocation, and the TaskManager offers allocated slots to the job’s JobMaster.
- Deploy replacement task attempts and restore state. The JobManager schedules tasks with the required recovery metadata. The workers restore checkpointed state and source positions before processing resumes.
With production checkpoint storage configured on a durable filesystem or object store, state can be restored from locations such as HDFS or Amazon S3. Losing the old worker does not, by itself, destroy the completed checkpoint stored there. Recovery still requires that the checkpoint remains available and accessible.
Flink’s native Kubernetes integration supports dynamic TaskManager allocation. However, not every worker failure requires a new pod: sufficient capacity may already exist elsewhere in the cluster.
A New JVM Does Not Always Mean a New Pod
Kubernetes distinguishes a container restart from pod replacement:
| Recovery event | TaskManager JVM | Kubernetes pod |
|---|---|---|
| Task recovery on a surviving worker | Can remain running | Can remain unchanged |
| Restarting a terminated container | A fresh JVM starts | The same pod can remain, depending on restart policy |
| Replacing a failed, deleted, or evicted pod | A fresh JVM starts in the replacement worker | The replacement pod has a new UID |
The Kubernetes pod lifecycle documentation explains that a container can restart inside an existing pod. A replacement pod is a separate object, even if its name is reused.
Therefore, an OOMKilled container does not prove that Kubernetes created a new pod. Check the container’s restart count, termination details, and pod UID.
What Can Be Recovered Within a Surviving Worker?
An ordinary operator exception, such as an unhandled NullPointerException or parsing error, can fail a task without terminating an otherwise healthy TaskManager JVM.
In that situation, Flink can cancel the affected execution attempts, create new task attempts on available slots, and restore their state while keeping the worker processes alive. It may reuse slots on the same TaskManager without requesting new containers.
This is sometimes informally called an in-place task restart, but it is not a promise that the same task thread or exact slot will be reused. The scheduler chooses the placement, and the failover strategy determines which other tasks must recover.
The useful distinction is process survival: task-level recovery can reuse a live worker; a terminated TaskManager JVM cannot be reused.
5. What Happens to State and Input During Recovery?
When recovery uses an available completed checkpoint, Flink restores the relevant operator state and checkpointed source positions, then resumes processing from that consistent recovery point.
An incomplete or failed checkpoint is not a recovery point. If no completed checkpoint is available, checkpoint-based recovery cannot restore previously accumulated state; startup behavior then depends on the job and its sources.
Replay also depends on the source’s ability to retain and reproduce the required records. The application may process records again after a restart. Exactly-once effects in external systems require appropriately configured sources and sinks; arbitrary side effects in user code are not automatically made exactly-once.
6. A Practical Restart-Diagnosis Checklist
- Start with the JobManager failure cause. Determine whether the event was a checkpoint-tolerance violation, an operator exception, or a lost worker.
- Inspect checkpoint history. Compare failure reasons, durations, and the age of the last successfully completed checkpoint.
- Correlate TaskManager logs and infrastructure events. Look for heap errors, long GC pauses,
OOMKilled, evictions, and heartbeat failures. - Identify the layer that restarted. Compare task attempts, TaskManager registration events, container restart counts, and pod UIDs. Do not infer worker replacement from a task restart alone.
- Check storage and backpressure. Investigate checkpoint-write errors, permissions, storage latency, and slow downstream operators.
- Review the effective recovery configuration. Check checkpoint tolerance, timeout, restart strategy, and any job-level overrides.
- Fix the cause before increasing retry limits. More tolerated failures or retries can mask a persistent problem without restoring reliable recovery.
Takeaway
Repeated checkpoint failures can explain a Flink restart, but only certain checkpoint failures count toward the tolerance limit. Task exceptions, memory exhaustion, worker loss, and network problems can independently trigger recovery.
The failure reason explains why recovery began. The restart strategy controls whether and when it can retry. The failover strategy determines which tasks restart.
Finally, distinguish a new task attempt from a new worker process: a healthy TaskManager can survive task recovery, but a killed JVM requires another live process to execute the recovered tasks.