# A container restarted 39,352 times. Every exit code was 0.

> Source: <https://dev.to/cxtao/a-container-restarted-39352-times-every-exit-code-was-0-2g6i>
> Published: 2026-09-19 07:05:01+00:00

A container on one of my servers had restarted **39,352 times**. Every single exit code was `0`.

That number is why nobody noticed. Monitoring watches for crashes, and this was not a crash. The process started, found nothing to do, exited *successfully* — and `restart: unless-stopped` dutifully brought it back. About 39,000 times.

This turned into one of those debugging sessions where every layer is behaving "correctly" and the system as a whole is broken. Here's the walk-through, and the one metric I now trust more than exit codes.

The service was an MCP server running in **stdio mode**. In stdio mode the process talks over standard input/output — it reads requests from `stdin` and writes responses to `stdout`.

Here's the compose block, simplified:

```
services:
  mcp:
    image: my/mcp-server
    restart: unless-stopped
    # note what's NOT here:
    # stdin_open: true
    # tty: true
```

Without `stdin_open` (the compose equivalent of `docker run -i`), the container gets **no open standard input**. So the MCP server boots, reads from `stdin`, and immediately hits **EOF**. There's nothing to read and never will be. It does the correct thing on EOF: it shuts down cleanly and exits `0`.

`restart: unless-stopped` sees a stopped container and restarts it. The new process boots, reads `stdin`, hits EOF, exits `0`. Restart. Boot. EOF. Exit `0`. Restart.

Every individual decision in that loop is right. The process *should* exit when its input stream closes. The restart policy *should* revive a service that stopped without being told to. Compose it together and you get a clean, successful, infinite loop that a crash-based alert will never fire on.

The fix is one line — give it a stdin to hold open:

```
    stdin_open: true
    tty: true
```

But the fix isn't the interesting part. The interesting part is why it stayed invisible for 39,352 iterations.

While I was in there, I looked at the other containers on the same box. Two of them had been marked `unhealthy` for **four weeks**. Both were completely fine the whole time.

`localhost` from a Node 18 process. Since Node 17, Node no longer reorders DNS results, so `::1` first`ECONNREFUSED`, forever — against a service that was answering fine on `127.0.0.1`.

``` js
// Node 18+: this can resolve to ::1 and miss an IPv4-only server
const res = await fetch("http://localhost:3000/health");

// Force IPv4 if that's what your service binds:
const res = await fetch("http://127.0.0.1:3000/health");
```

So on one machine, at the same time:

`unhealthy`` exit 0`
The health signal wasn't just wrong. It was inverted in both directions at once. If I'd trusted it, I'd have "fixed" the two healthy ones and never looked at the broken one.

`stdin_open: true` + `tty: true` for the stdio service.`docker run`, fails in a health check" as an IPv4/IPv6 smell).
That last one is the takeaway.

Exit `0` only tells you the process *agreed to leave*. It does not tell you it *should have*.

Restart count, by contrast, is honest. A number that climbs into the thousands means something is wrong regardless of how politely each instance exited. It's a better smoke alarm than exit code, and a far better one than a health check that can be pointed at the wrong port or the wrong IP stack.

Cheap checks worth stealing:

`stdin_open` will exit cleanly on boot. "Clean" is not the same as "correct."
What's the longest a silent restart loop has run in your infrastructure before anyone noticed?
