Is the box stopped, or is it wedged?

A shared remote dev instance stopped answering me one morning. SSH hung. The web services it hosts timed out in the browser. Nothing in my terminal produced output, just a cursor and then a timeout.

The box is a 32-core, 61GB instance that runs about fifty services for a sales engagement platform, plus the containers they depend on. When it goes quiet, work stops for whoever is using it.

I assumed it was stopped and started it. That cost fifteen minutes and fixed nothing, because the instance had been running the entire time. It was accepting network connections throughout, but could not schedule a single userspace process fast enough to answer me.

Those two states, powered off and wedged on exhausted memory, produce the same symptoms from outside. They need opposite responses. Telling them apart takes about twenty seconds.

Ping is worthless here

The first instinct is ping. Mine was. I got 100% packet loss against a box that was, at that same moment, serving HTTP traffic to another engineer.

ICMP is filtered at the security group. It is filtered in most cloud networks by default, and nobody opens it because nobody thinks about it until the day they want a liveness check. So ping reports total silence whether the machine is dead, alive and healthy, or alive and thrashing. It carries no information at all.

Drop ping from your checks for whether a remote machine is alive. It answers a question about ICMP policy, not about the machine.

The one test that separates the two cases

What you actually want to know is whether something in the kernel is still completing a TCP handshake on port 22. Netcat answers that without needing a shell. -z sends no data and reports only whether the port answered, and -G 10 caps the connect attempt at ten seconds:

nc -z -G 10 <ip> 22

The two outcomes mean different things.

Connection refused, or unreachable, and the instance really is off. Boot it and get on with your day.

Connection accepted but ssh still fails, and the instance is up and wedged.

The TCP handshake for a listening socket is completed by the kernel. sshd does not have to run for the connection to be accepted; the kernel puts it on the accept queue. What sshd does have to run for is the next step, writing its version banner. That is userspace. On a box where every runnable process is stuck behind an I/O queue, sshd gets accepted into the connection and then never gets scheduled to say hello.

So port 22 accepting while the login never completes is the fingerprint of a live machine that cannot schedule userspace work, not a flaky network in front of a dead one.

Three error messages, one cause

Because this is a scheduling race, the failure is inconsistent. Over one morning, the same box in the same condition gave me all of these:

Connection timed out during banner exchange
kex_exchange_identification: read: Connection reset by peer

and, most often, a plain hang until ConnectTimeout fired with no message at all.

I wasted real time treating these as three separate problems and searching for each one. They are one problem. The connection sometimes gets far enough to be reset, sometimes not. Read any of them, on a box whose port 22 accepts, as the same diagnosis.

You can usually still get a shell if you are patient about it. Raise the timeouts well past anything that feels reasonable and retry in a loop:

for i in $(seq 1 8); do
  OUT=$(ssh -o ConnectTimeout=120 -o ServerAliveInterval=20 \
            -o ServerAliveCountMax=10 box "uptime; free -g | head -3" 2>&1)
  echo "$OUT" | grep -qE 'banner exchange|Connection reset|timed out' || { echo "$OUT"; break; }
  sleep 25
done

Eight attempts, twenty-five seconds apart, usually got me in. Keep each remote command small and single purpose, because long compound commands on a wedged box get dropped part way through and you cannot tell which half ran. And macOS has no timeout(1), so the habitual timeout 30 ssh ... wrapper is not available there. Use ssh's own timeout options instead.

Load average 227 is not a CPU problem

Once I was in, uptime showed a load average climbing between 175 and 227 on 32 cores. That looks like something is eating the machine, so I went looking for it with ps -eo pid,pcpu,args --sort=-pcpu.

Nothing was above roughly 63% CPU. There was no runaway loop and no compile storm. The highest consumer was a database process doing ordinary work.

This is where a lot of people, me included, lose half an hour. Linux load average does not measure CPU demand. It counts tasks that are runnable plus tasks in uninterruptible sleep, the D state, which is mostly processes blocked on disk I/O that the kernel will not let you interrupt. A machine with a hundred processes each waiting on a slow block device reports a load of a hundred while the CPUs sit idle.

So load in the 200s with idle CPUs means processes are piling up on I/O. And on a box with no unusual disk workload, the thing that turns ordinary memory access into disk I/O is swap.

free -g settled it in one line:

              total  used  free  shared  buff/cache  available
Mem:             61    58     0       0           2          2
Swap:            15    15     0

Fifteen gigabytes of swap, fifteen in use, zero free. Every page fault was a disk read against a device with a queue it could not drain, and every process that touched memory joined the D-state queue. That is where the load number came from. The box was paging itself to death.

The process that looked like an intruder

Sorting by resident memory instead of CPU found the cause immediately:

ps -eo pid,rss,args --sort=-rss | head -5

One process at 24.34GB RSS, about 40% of the machine, running as root:

/opt/code/localstack/.venv/bin/python -m localstack.runtime.main

Everything else on that box runs as an unprivileged user under Node. A root-owned Python process with a path under /opt/code looks nothing like the rest of the system. I had an AI agent investigating in parallel, and it flagged this process as a possible intruder and refused to touch it on security grounds. That was a defensible read of the evidence and completely wrong.

It was the LocalStack container, the local AWS emulator the services develop against. Containers show up in the host process table with their own internal paths and their own uid, and nothing in ps tells you they are containerized. The container had leaked from a normal idle footprint of a few hundred megabytes up to 24GB over several days of uptime, because it was configured to keep every emulated Lambda execution environment warm for 24 hours across dozens of functions.

Before deciding that any process is stray, map its PID to a container:

grep -a 'docker\|containerd' /proc/<pid>/cgroup

If that prints a container ID, the process belongs to something you started. Kill it through the container, not through the PID.

Disk-full and memory-full are twins

Two months earlier I had debugged the same outward symptoms on the same box and the cause was completely different. Many services were unhealthy, restart counts ran into the hundreds of thousands, and everything was slow. One service had accumulated 213,127 process-manager restarts and contained no bug whatsoever. The root filesystem was at 131G of 131G with zero bytes free, and every write it attempted failed with ENOSPC.

The three infrastructure containers died in three different ways from one cause: the AWS emulator exited 137 (SIGKILL), Redis exited 0 (a clean shutdown), Elasticsearch exited 143 (SIGTERM). Three exit codes, one disk-full event. If you triage by exit code you will invent three unrelated stories.

Disk exhaustion and memory exhaustion present almost identically from the outside and need opposite first commands. Run free -g and df -h before you touch a single service.

SymptomRead asFirst command
No SSH, no HTTP, nothingUnknown; test livenessnc -z -G 10 <ip> 22
Port 22 refusedInstance is offStart it
Port 22 accepts, SSH banner failsAlive, unschedulableRetry loop, then free -g
High load, no process above ~60% CPUI/O wait pileup, not CPUfree -g and df -h
Swap at 100%Memory exhaustiondocker stats, sort ps by RSS
ENOSPC in logs, huge restart countsDisk exhaustiondf -h

What the fix looked like

Restarting the leaked container took its memory from 24.88GiB to 759MiB. System memory used went from 58GB to 34GB, available from 2GB to 25GB. The fifteen-minute load average fell from 227 to 48 and kept falling. SSH went from needing four or five retries per command to connecting first time.

That is symptom relief rather than a fix, and the box wedged the same way again within a week. The actual fix is a change to the shared Docker Compose file that every engineer's instance inherits, turning off the debug mode and the 24-hour keepalive that hold those execution environments open. Until that lands, a scheduled weekly restart of the container costs a minute and prevents the whole morning.

What I keep coming back to is the fifteen minutes I spent booting a machine that was already running. The only evidence I had was an absence, and an absence looks the same no matter what causes it. Every diagnostic step after that cost me seconds. The expensive move was acting before I ran a test that could come back two different ways.