Combined Failure Simulator: Break a Layer, Watch It Propagate
Application → kernel → network → remote: exhaust descriptors, fill a buffer, block a thread, drop packets, add latency, kill the process, restart the server — and follow each failure across the layers to the symptom the user sees and the tool that proves it.
Builds on Scheduling, Paging, I/O, Synchronization and Sockets in the OS roadmap.
The problem
The model: four layers, two machines
The simulator models a client application, its kernel (descriptor table, socket buffers, TCP state), the network between (loss, delay), and a server with the same three layers in reverse. Every control injects one fault into one layer; the display shows the fault propagating as state changes — queue depths, window sizes, thread states, error codes — until it reaches the user as a symptom. The numbers are simulated: the timings and sizes are chosen to make the propagation visible, not measured from a real system. The propagation *paths* are real, and they are what to learn.
The lesson is in the direction of travel. Faults in the application propagate down and across: a blocked thread stops draining a buffer, the buffer’s fullness becomes a window, the window crosses the network as an ACK field, and it stops a thread on the other machine. Faults in the network propagate up: a lost packet becomes a retransmit timer, then a stalled send buffer, then a blocked write(), then a request timeout in user code. Learning to run these chains in both directions is the skill the Capstone: Three Seconds from Warsaw tests.
The seven controls
Each row of the matrix is one control: where the fault lands, how it propagates, what the user experiences, and the command that confirms it on a Linux host. The confirming tool is chosen to answer one question — "is the fault in this layer?" — because that is how a real diagnosis proceeds (see The OS Debugging Playbook: Four Symptoms, Fourteen Causes and The Tools, and Which Layer Each One Answers). Read the rows as chains, not as facts.
Two of the controls deserve a closer look because their propagation crosses domains twice. Block thread on the server: the handler thread stops calling read(); the server kernel’s receive buffer for that connection fills; the window advertised to the client shrinks to zero; the client’s kernel stops sending and starts zero-window probes; the client’s send buffer fills; the client’s write() blocks (or returns EAGAIN, or its stream returns false); the client’s request times out at the application layer. Six state changes, three layers, two machines — from one thread doing CPU work. Drop packets: the client’s segment is lost; the server never ACKs; the client’s retransmission timer (RTO, minimum 200 ms on Linux) fires and resends with cwnd collapsed; on repeated loss the RTO doubles each time; the send buffer fills behind the unacknowledged bytes; write() blocks; the request slows from milliseconds to seconds with no error until a timeout — the classic "the network is fine, ping works" incident (see Packet Loss: Duplicate ACKs, Fast Retransmit and the RTO and the challenge A 1 Gbit/s link, and the backup crawls at 9 Mbit/s).
| Control | Failing layer | Propagation | Symptom the user sees | Tool that confirms it |
|---|---|---|---|---|
| Exhaust file descriptors | Server kernel: per-process fd table | accept() → EMFILE; connections stay in accept queue; loop may spin; backlog overflows; client SYNs dropped | connect hangs or times out; server CPU 100% doing nothing | ls /proc/<pid>/fd | wc -l vs ulimit -n; strace shows EMFILE; ss -ltn Recv-Q at limit |
| Fill socket buffer | Server kernel: receive buffer | app not reading → Recv-Q at max → rwnd 0 → client send buffer fills → client write() blocks/EAGAIN | client request hangs; sender "waiting on network" | ss -tmi: Recv-Q full on server, Send-Q full and snd_wnd 0 on client |
| Block thread | Server app: handler thread / event loop | no read() → receive buffer fills → rwnd 0 → sender stalls; in an event loop, every connection stalls | all requests slow or hung; timeouts | top shows R (CPU) or D/S (blocked); py-spy/jstack/perf on the thread; ss shows Recv-Q |
| Drop packets | Network | lost segment → no ACK → RTO (≥200 ms) → cwnd collapse → send buffer backs up → write() blocks | requests slow, no errors, then timeout; ping may look fine | ss -ti retrans counter; nstat TcpRetransSegs; tcpdump shows retransmissions; mtr shows loss |
| Add latency | Network | RTT up → handshake, TLS, every round trip up → throughput capped at buffer/RTT → cwnd growth slow | everything slower proportionally; downloads capped | ping/mtr RTT; ss -ti rtt; curl -w timings show connect and TTFB scaling with RTT |
| Kill process | Server app | kernel closes all fds → FIN (or RST if data unread) to every client → listen socket gone → new connects get RST | ECONNRESET on in-flight requests; ECONNREFUSED on new ones | ss -ltn shows nothing listening; dmesg/journal for OOM-kill or signal; client sees RST in tcpdump |
| Restart server | Server app + kernel | listen socket reappears; bind may fail with EADDRINUSE without SO_REUSEADDR; backlog refills; cold caches; connection storm | brief ECONNREFUSED then a slow first minute; thundering-herd retries | ss -ltn shows LISTEN again; strace bind; latency graph shows the cold-start hump |
Reading a propagation chain
The ladder below is the "Block thread" chain end to end, with the state that changes at each rung. Notice that every rung is observable with a different tool on a different machine, and that an engineer who only has one of those tools will name the wrong layer: the client team sees a network stall; the network team sees a zero window from the server and a healthy path; the server team sees a busy thread and a healthy socket. All three are right about their layer and wrong about the cause unless they read the chain.
The general procedure: find the rung where the state is at its limit — a buffer at its size, a window at zero, a descriptor count at ulimit, a queue at its backlog — then ask what drains that state and why it stopped. The drain of a receive buffer is a thread; the drain of a send buffer is the network and the far window; the drain of an accept queue is accept(); the drain of a retransmit queue is an ACK. Whatever should be draining it and is not is the next rung up.
- Server handler thread runs a 30 s CPU loopstate: thread R (running), not in read()↓
- Server receive buffer fillsstate: Recv-Q → SO_RCVBUF↓
- Server advertises rwnd 0state: window field in every ACK = 0↓
- Client TCP stops sending; zero-window probesstate: snd_wnd 0; probes with backoff↓
- Client send buffer fillsstate: Send-Q → SO_SNDBUF↓
- Client write() blocks / EAGAIN / falsestate: client thread S (sleeping) or stream paused↓
- Client request deadline firessymptom: timeout error; "network is slow"
Confirming, not guessing
The transcript below is the same chain seen from the two hosts with the tools from the matrix. The habit to build is to run both sides before naming a cause: a stalled connection has a sender and a receiver, and the kernel on each records which queue is full. When the queues are empty on both sides and the request is still slow, the fault is above the kernel (the application is slow to respond, not slow to read) or in a layer the kernel cannot see (DNS, TLS, a proxy).
The Break the OS: Predict, Break, Diagnose and Network Failure Lab: Predict, Inject, Observe, Diagnose simulators inject faults in one domain each; this one exists because production incidents do not respect the boundary. The capstones for each domain — Capstone: A Server With 50,000 Concurrent Connections and Capstone: What Happens When You Visit https://example.com — and the Capstone: Three Seconds from Warsaw ask you to do this without the simulator’s labels.
server$ top -H -p $(pidof api) PID USER %CPU S COMMAND 8813 app 99.7 R api <- one thread running, not in read() server$ ss -tmi sport = :8080 | head -3 ESTAB 262144 0 10.0.0.9:8080 10.0.0.5:51120 <- Recv-Q at SO_RCVBUF: app not reading skmem:(r262144,rb262144,...) client$ ss -tmi dst 10.0.0.9 ESTAB 0 4194304 10.0.0.5:51120 10.0.0.9:8080 <- Send-Q at SO_SNDBUF ... snd_wnd:0 ... probes:7 ... <- zero window, probing with backoff client$ strace -p $(pidof worker) -e write write(7, "...", 65536 <- blocked; never returns
Key points
- Application faults propagate down and across: a thread that stops reading becomes a zero window on the wire and a blocked
write()on the other machine. - Network faults propagate up: a lost segment becomes an RTO, a collapsed
cwnd, a full send buffer, a blockedwrite(), a request timeout — with no error until the deadline. - Every rung of a chain has a state that can be observed with a specific tool on a specific host; diagnosis is finding the rung whose state is at its limit and asking what should drain it.
- Descriptor exhaustion shows as
EMFILEinstraceand a full accept queue inss -ltn; a killed server shows asECONNRESETfor in-flight andECONNREFUSEDfor new connections; a restart shows as a cold-start latency hump and a retry storm. - Run the tools on both ends before naming a layer; each team’s tool is right about its layer and wrong about the cause.
- The simulator’s numbers are simulated; its propagation paths are real.
Why does this exist?
Mechanisms are answers to constraints. Open each question before reading the answer.
▸Why does a CPU-bound thread on the server look like a network problem to the client?
Because the only thing the client can observe is the wire, and on the wire the server’s inability to read appears as a zero receive window — a flow-control message. Flow control is designed to make a slow application look like "please wait" to the peer; it succeeds, and the peer cannot tell why.
▸Why does packet loss produce slowness rather than errors?
TCP’s contract is reliable delivery, so it retransmits silently with exponential backoff rather than reporting loss. The application sees delay, and only its own deadline turns delay into an error. This is by design and is why "slow, no errors" should prompt ss -ti for retransmits.
▸Why is a restart a failure mode at all?
Because the listen socket disappears and reappears (refused connections in between, or EADDRINUSE if the old socket lingers), every client reconnects at once (a connection storm into an empty backlog), and every cache — page cache, JIT, connection pools, DNS — is cold. A restart is several small faults in sequence.
OS + network failure simulator
All four layers healthy. Choose a fault.
How it fails
What the failure looks like from inside real software.Reference · showHide
- Descriptor exhaustion on a server whose accept loop retries on
EMFILEwithout sleeping: 100% CPU, no connections accepted, and the backlog overflows so new clients time out instead of getting an error. - An event-loop server with one blocked handler: every client’s
write()stalls at once; the client fleet’s connection pools drain; a retry storm arrives when the handler finishes. - 5% packet loss on one path: transfers slow 10× with zero errors; the dashboard shows healthy servers and healthy links because the loss is on a middlebox nobody graphs.
- Server killed by the OOM killer mid-response: clients see
ECONNRESETwith a partial body; those that retried non-idempotent requests duplicated writes. - Restart without
SO_REUSEADDR:bind: Address already in usefor up to 60 s ofTIME_WAIT; the service is down for a minute after every deploy.
Check yourself
Answer out loud or on paper first, then compare. These come from the interview questions linked to this lesson.
Requests to your API take 3 seconds at p99, but the server sits at 5% CPU and the handler itself measures 20 ms. Where can the other 2.98 seconds be, and how would you find them?
Show a strong answerHide the answer
The handler’s 20 ms is measured from the moment the framework calls it — a request has a long life before and after that point, and none of it burns CPU. Lay out the timeline (Where the Time Goes: The Request Timeline): client DNS lookup → TCP handshake → TLS handshake → request bytes cross the network → the kernel’s accept queue → the application’s own queue (thread pool, event loop) → the handler → response bytes written to the socket buffer → transferred to the client → parsed. "Idle CPU plus slow requests" means the request is *waiting*, and each stage has a characteristic wait.
Exact values are fingerprints. A p99 of ~1 s or ~3 s is the signature of a lost SYN: Linux retransmits at 1 s, then 3 s, then 7 s, so a handshake whose first SYN was dropped — by a full accept queue, a conntrack table at capacity, or a firewall — completes at exactly 1 or 3 s (The Three-Way Handshake, TCP Debugging: Reading the Handshake on the Wire). Check
nstat -az TcpExtListenOverflows TcpExtListenDropsandss -ltnfor Recv-Q at the backlog limit. Steps of ~200 ms or multiples are retransmission timeouts on established connections (RTO_MIN, Packet Loss: Duplicate ACKs, Fast Retransmit and the RTO); ~40 ms per small write is the Nagle + delayed-ACK interaction; exactly 5 s is the glibc DNS resolver timeout — the first nameserver inresolv.confis dead or drops UDP, or an AAAA lookup goes unanswered; 1–3 RTTs of extra latency on *every* request means no keep-alive, so each request re-runs the TCP and TLS handshakes (Keep-Alive and Connection Reuse).Queueing without CPU is the other big family. A thread pool of 32 workers all blocked on a downstream call with a 3 s timeout serves 20 ms handlers with a 3 s wait — the thread-pool queue length, not CPU, is the saturated resource (The Thread Pool Server). An event loop stalled on a synchronous call queues everything behind it. A slow client or a small socket buffer makes
write()fast (it copies into the kernel) but the *transfer* slow, so server-side timing ends before the client has received anything; the LB then reports a long response time the app never saw (What Happens When the Receiver Is Slow). And on the client side, browsers queue requests beyond six per host — DevTools shows that as "Stalled" — and a proxy in between may buffer.Find it by measuring each hop, not the handler. From a client:
Full interview question, with follow-ups and red flags →curl -w "%{time_namelookup} %{time_connect} %{time_appconnect} %{time_starttransfer} %{time_total}"splits DNS, TCP, TLS and time-to-first-byte. At the balancer: ALBrequest_processing_time/target_processing_time/response_processing_time, or nginx$request_timeversus$upstream_connect_time,$upstream_header_time,$upstream_response_time— the gap betweenrequest_timeandupstream_response_timeis client or network. On the server:ss -tiforretrans,rtoandcwndper connection, thread-pool and event-loop lag metrics, and a distributed-tracing span opened at the *ingress* rather than in the handler. Compare p50 to p99: a flat p50 with a spiky p99 at round values is a timer; a smeared p99 is a queue.A service starts logging
EMFILE: too many open filesafter about a day of uptime. How do you approach it? Is raising the limit the fix?Show a strong answerHide the answer
EMFILEmeans the per-process descriptor table is full — the softRLIMIT_NOFILE, often 1,024 by default and raised by the service manager to 65,536 (label: Linux/Unix;ENFILEis the system-wide table). The first question is not "how high" but "what is in the table":ls /proc/<pid>/fd | wc -lsampled every few minutes tells you whether the count tracks load (bounded, fine) or grows monotonically since start (a leak) (File Descriptors).Then classify.
lsof -p <pid>(orls -l /proc/<pid>/fd) shows each descriptor’s type: regular files with a path, sockets with peers, pipes,anon_inodeentries for epoll/eventfd/timerfd. Hundreds of sockets to the same upstream is one story; hundreds of the same log path is another; thousands of pipes means child processes. For sockets,ss -tanp | grep <pid>gives the state: many `CLOSE_WAIT` means the peer closed and the application never calledclose()— a leak in the client code, not a kernel problem.TIME_WAITsockets, by contrast, hold no descriptor and are the kernel’s business (The Socket: A Descriptor With Two Kernel Buffers Behind It).Common causes: an HTTP client or database connection created per request and never closed or pooled; a response body not consumed/closed (
resp.Body.Close()in Go, unconsumed streams in Node.js); a file opened in a code path whose error branch skipsclose; akeepAliveagent per request whose idle sockets outlive any reference; child processes inheriting descriptors. Fix the ownership — pooling,try/finally, RAII,using— and add a descriptor-count metric so the next leak is a graph, not an outage (The OS Debugging Playbook: Four Symptoms, Fourteen Causes).Raising the limit is the *second* step, and legitimate: a server holding 20,000 connections needs a table that size, and the soft limit should be set at the hard limit (
Full interview question, with follow-ups and red flags →LimitNOFILE=in systemd,worker_rlimit_nofilein nginx). But raising it for a leak only moves the failure to a bigger, later, more confusing incident.The p99 is exactly 1.02 s and p99.9 exactly 3.02 s. What is the 20 ms?
Show a strong answerHide the answer
The handler. The 1 s and 3 s are SYN retransmit timers; the handshake is being dropped, most likely accept-queue overflow or conntrack.
Full interview question, with follow-ups and red flags →