Network faults
A distributed system fails at its links: one that is slow, one that loses
packets, one that stalls and then delivers everything at once, a node cut
off from one peer while it still reaches the others, a connection reset in
the middle of a transaction. machine net puts
those faults on the links between the containers of a run.
Each container has one link, which carries everything the container sends. A fault on the whole link acts on every packet the container sends. A match narrows a fault to some of those packets: the ones to one peer, of one protocol, of one port, or the TCP SYNs that open a connection. Each match has faults, a seed and counts of its own.
Every net command runs the machine until its kernel has made the change, so
the run moves forward.
1 | machine net app # each link and its faults |
Use cases
Each command follows machine net <run>.
| You want to know | Command |
|---|---|
| Does a client time out and retry when its server answers slowly? | delay db 2s |
| Does the protocol survive lost and duplicated packets? | loss db 10%, then duplicate db 5% |
| Does a leader election hold when one node is cut off? | partition node1 node2, then partition node1 node3 |
| What happens when only one direction fails? | partition db api --one-way |
| Does replication keep up over a slow link? | rate primary 1mbit --to replica |
| Does the protocol recover when the network damages packets? | corrupt db 1% |
| Does the client reconnect, and retry safely, when its connection is reset mid-transaction? | reset api --to db |
| What happens when a server’s responses to one client are lost, and nothing else? | loss db 100% --to api --port 5432 |
| Do messages that arrive late, after a leader change or a timeout, do harm? | hold node1 --for 10s |
| Does the cluster recover when the whole network stalls and comes back at once? | hold, run --within 3s, release |
| What happens if the network stalls at one exact point? | run --until <point>, then hold |
| Do established connections keep working while new ones cannot open? | loss api 100% --to db --syn |
| Does the cluster settle when a link keeps going down and coming back? | a loop of partition --for, below |
| What happens when a node cannot resolve a peer’s address? | loss db 100% --proto arp --to api, then arp flush api and arp flush db |
| What happens when a node holds a wrong MAC for a peer? | arp set api db 02:42:ac:12:00:99 |
| Did the fault drop the packets, or did the program never send them? | machine net app: each fault’s SENT and DROPPED, below |
| Which exact packet did the fault drop, and why? | loss db 30% --log, then read the decision log, below |
| What exactly went between two containers, to open in Wireshark? | tcpdump in the machine, in Capturing the packets, below |
Other commands cover the failures around a network fault:
- A refused connection, rather than one that times out:
machine inject app add syscall connect ECONNREFUSED --in /usr/bin/app, in Fault injection. - A node that freezes rather than one that is cut off:
machine containers app pause db --for 5s, in Container faults. - Clocks that disagree between nodes:
machine clock app jump +2s --container db, in Clock faults. - A cluster split into two groups: one
partitionfor each pair of containers across the split.
One link or all of them
Without a match, a fault is on everything the container sends. With --to,
it is on what the container sends to that one peer, and its other links stay
as they are:
1 | machine net app delay db 100ms --to api |
1 | SERVICE CONTAINER TO MATCH FAULTS SEED SENT DROPPED QUEUED |
A ping from api to db now takes 103ms, because db‘s replies to api
wait 100ms. A ping from nest to db still takes 0.04ms.
Packets a match takes get only the match’s faults, not the whole link’s:
after loss db 10% and then delay db 100ms --to api, what db sends to
api is delayed and none of it is lost. A packet two matches take gets the
faults of the one listed first.
Each verb changes the fault it names and keeps the others, so delay and then
loss give a link that is slow and lossy. A value of 0, or 0%, takes that
fault away. A jitter also reorders
packets, since each one leaves at its own time. reorder works by sending
some packets ahead of delayed ones, so it needs a delay on the same link or
match and is refused without one.
Matching packets: protocol, port and SYN
--proto tcp, --proto udp or --proto icmp takes the packets of one
protocol. --port 5432 takes the packets with 5432 as their source or
destination port, so on a server it takes its responses, and on a client its
requests; without --proto it takes both TCP and UDP. --syn takes the
TCP SYNs that open a connection. The options combine with each other and
with --to, and a packet must satisfy all of them. Every verb that sets a
fault takes them:
1 | machine net app loss db 100% --to api --port 5432 # every packet db sends api on port 5432 |
The first loses db’s responses to api on that port, and its SYN-ACKs too, so
api can open no new connection there either. The last leaves every
connection api already has to db working: only the packets that open a new
one are lost. A port belongs to TCP and UDP and a SYN to TCP, so
--proto icmp --port 5432 and --proto udp --syn are refused. A container
holds at most 15 matches besides its whole link.
Partitions
partition cuts two containers apart: everything each sends the other is
lost, and both still reach the rest of the cluster. --one-way cuts what the
first sends the second, and leaves the reverse. --proto, --port and
--syn cut those packets alone:
1 | machine net app partition db nest |
With --for 10s, both directions come back together after 10 seconds of
machine time.
A link that keeps failing and recovering is a loop of partitions, each
followed by a machine run:
1 | for i in 1 2 3 4 5; do |
Holding packets, then releasing them
hold keeps every packet the link sends, and release lets them all go at
once, in the order they were sent. Nothing is lost, so the peer receives
messages that were sent seconds ago: a stalled link that recovers, a
message that arrives after a leader change or after its sender timed out:
1 | machine net app hold node1 --to node2 # node1's messages to node2 wait |
--for 10s releases them after 10 seconds of machine time. A link holds 1000
full-size packets and drops the ones past them.
A held packet still counts against the send buffer of the socket that sent
it, about 208KB by net.core.wmem_default. Once that buffer is full, the
socket’s sends fail, or for TCP block, before the link’s queue is reached,
so one socket cannot fill a hold by itself. For example, when api sends db
1200 pings of 1400 bytes during a hold of db, db receives all 1200 and its
link holds 58 replies. The other 1142 replies fail in db’s kernel and count
as OutErrors in its /proc/net/snmp. With pings of 56 bytes, 159 replies
are held.
Without a container, hold holds every link at the instruction the
machine is stopped at, and all networking between the containers stops
there. release or heal without a container lets every packet go:
1 | machine net app hold # the whole cluster's network stops here |
The hold is part of the recording, so a replay holds at the same point, and a checkpoint taken during a hold keeps it. Run the machine to an exact point first, and the hold starts at that point:
1 | machine run app --until 'console~cluster ready' # stop where the cluster is ready |
For example, with api pinging db every 100 milliseconds, db receives none of
api’s requests while the links are held and the fault is set. After the
release, db receives the 47 held and later requests, the new fault drops
all 47 replies, and the listing’s DROPPED reads 47. No packet crosses a
link under the old faults after the hold.
The machine’s programs and timers keep running during a hold. A retransmission or an application timeout can expire while the links are held. To hold for a time, run the machine for that time between the two commands:
1 | machine net app hold |
For example, with api pinging db every 250 milliseconds, the 3 replies sent before the hold arrive, none arrives in 3 seconds of hold, and all 20 arrive after the release.
A container on the machine’s network, or on no network, has no link of its own, so a hold does not reach it, and the listing shows its row with dashes. A container that shares another container’s network sends on that container’s link, so holding that link holds its packets too. A hold also does not reach what a process outside every container sends. If a container’s link could not be held, the listing names it.
Resetting connections
reset aborts TCP connections. The container’s side of each connection is
aborted, and the peer receives a TCP reset, as from a middlebox that dropped
the connection or a server that restarted. What a program sees depends on
the call it makes. On the aborted side, data already received can still be
read. The first call that does not read received data fails with
ECONNABORTED: a write, or a read after all received data is read. After
that, a write fails with EPIPE, and a read returns the remaining received
data, then end of file. On the peer, the first call fails with
ECONNRESET, and later calls behave the same way. Unlike a partition, a reset
makes nothing wait for a timeout:
1 | machine net app reset api --to db # api's connections to db |
A listening socket stays open, so the server takes new connections at once.
Address resolution
A container finds a peer’s MAC by ARP and keeps it in its neighbour table.
--proto arp puts a fault on the ARP frames a container sends, and with
--to on those about one peer: its requests for the peer’s address and its
replies to the peer. A fault on ARP acts when a container resolves a peer
again, so flush the tables to see it at once. With db’s replies lost, api
cannot resolve db, while nest still reaches it:
1 | machine net app loss db 100% --proto arp --to api |
machine net app arp shows and changes a container’s neighbour table:
1 | machine net app arp show api |
1 | INTERFACE ADDRESS PEER MAC STATE |
1 | machine net app arp set api db 02:42:ac:12:00:99 # api sends db's frames to a MAC nobody has |
An entry made by arp set is permanent, so ARP never corrects it: api
reaches db again only after arp delete. A stale entry is still used; at
the next packet the kernel checks it by ARP within seconds, unless the
connection’s own traffic confirms the peer first. The table is part of the
machine, so a replay makes the same changes. A container that docker starts
again begins with an empty table, as a host that restarts does.
The decision log
--log writes each decision a fault makes to a log: which packet it took,
and whether it dropped it, delayed it, duplicated it, corrupted it or sent it
ahead. It answers which exact packet a fault dropped, which the counts and a
capture do not. --no-log with the same fault stops it:
1 | machine net app loss db 30% --to nest --seed 7 --log # the link's decisions are logged |
The machine’s kernel writes one line per decision, where the fault decides, to
/output/drop/.machine/net/<container>.log. The .machine folder holds the
files the machine itself writes, apart from a program’s own, and it is under
drop, so a run stores the log only when it keeps that output. When a run
keeps that output from its creation, its log can be read at any time:
1 | machine create app --disk app --keep-output /output/drop/.machine/net |
machine output prints the last 25 lines unless -n says otherwise; -n :
prints every line. The kernel writes the lines in batches, at most 1
millisecond of machine time after the first line of a batch. Lines decided
in the last millisecond before the machine stops reach the run when the
machine runs again, and a checkpoint keeps them. Run the machine for 10
milliseconds, with machine run app --within 10ms, before reading the last
packets’ lines.
A run that does not keep the log still makes it, and replay brings it back. Fork a branch from a checkpoint before the stretch, keeping that output, and the branch replays the stretch and stores the same lines:
1 | machine checkpoint app before |
1 | 2026-03-01T00:01:31.691986Z #8 to compose-nest-1 pass ICMP 172.18.0.4 > 172.18.0.3 echo reply id 25 seq 0 len 84 |
Each line has the machine’s date, the packet’s number on its link, the
match, the decision and the packet with its IP length. The number counts
every packet the link carried since the container started, logged or not,
so a later stretch starts at a higher number: here the link had carried 7
packets before the ping. The 8 drops of the 20 lines are the 8 pings the
ping lost, and DROPPED in the listing reads 8. A replay from a checkpoint
writes the same log, byte for byte.
The decisions are pass, drop, delay with the time the fault drew,
ahead for a packet reorder sent before the delayed ones, and duplicate
and corrupt beside the first word. drop limit is a packet dropped
because the fault’s queue already held 1000 delayed packets, and drop hold
one dropped because a hold already held 1000 full-size packets; DROPPED
counts both.
Every packet the link carries has its line and its number,
and a packet a hold drops has a second line, drop hold, under the number
of its first. A duplicated packet has two lines: the
original says duplicate, and the copy, logged first, says copy. A delay
is what the fault drew; the packet can leave later by the machine’s timer
slack, as a timer can. A container on two networks writes both links’
decisions to the one file.
Every decision is logged; none is dropped however fast the packets come. For
example, a 200MB TCP transfer under a logged fault decides 19,586 packets,
the log holds 19,586 lines, and the listing’s SENT and DROPPED add up to
them.
Each decision costs about 32 microseconds of machine time to write, and a decision is a packet as the kernel hands the link, whatever its size. A 50MB TCP transfer under a logged fault takes 0.66 seconds of machine time on average, against 0.47 seconds under the same fault without the log, because its packets are large. Small packets cost the same each, so a stream of them spends far more of its time on the log; 10,000 packets cost about 0.32 seconds. Log the stretch being examined, not a whole run. A fault decides per packet, never per program message: see the limits below on TCP units and retransmission.
Seeds, replay and --for
Loss, jitter, duplicate, corrupt and reorder decide each packet by chance,
from the link’s seed. Give one with --seed, or the link draws one and shows
it. A delay or a rate alone draws nothing, and shows no seed. A link keeps
its seed through later changes. The run records every change, so a replay
delays and drops exactly the same packets, and so does a branch forked from a
checkpoint before them.
A change to a link starts its draws again from the seed: loss db 10% --seed 7, then delay db 50ms, loses packets from the start of seed 7’s
sequence again. Which packet corrupt changes, and which byte and bit
of it, follow the seed.
A checkpoint keeps a link’s faults: a rewind to it brings them back. A
container that docker starts again, after containers kill --restart or a
crash, gets its faults back, toward each peer at the address it has now.
--for 30s sets back what its command set after 30 seconds of machine time,
and leaves the rest of the link as it is then:
1 | machine net app loss api 100% --for 3s # everything api sends lost for 3 seconds |
A heal takes every fault off and releases what a hold keeps. A heal, and a
--for that ends, act on new packets: a packet the link already delays
still leaves at its time.
What a fault did
SENT, DROPPED and QUEUED count what each fault did with the packets
it took. They count from when the match, or the whole link, first got a
fault, and a later change to it keeps counting. SENT is the packets it
passed on, a duplicate counting once more. DROPPED is the packets it lost,
by loss, or past what a hold or a delay has room for. QUEUED is the packets it
holds now, delayed or held: neither sent nor dropped yet. After 50 pings
from api to db with loss db 30% --to api --seed 9, the row of that match:
1 | SERVICE CONTAINER TO MATCH FAULTS SEED SENT DROPPED QUEUED |
The ping prints 50 packets transmitted, 36 packets received, so the 14
db dropped are the 14 api lost. A hold shows what it holds as QUEUED until
the release. The counts are what the fault processed, packet by packet, not
a measure of its probability: over many packets 30% loss drops close to 30%
of them, and over a few the count can be anything. A container that docker
starts again counts from 0, and so does one a network is disconnected from.
The counts are of packets as the fault decides them, the same unit as the
log’s lines, so a large TCP write that reaches the fault as one packet counts
once.
The counts are packets on the link, not sends by a program. A TCP write can
wait in the socket’s buffer, and the kernel retransmits without a system
call. machine catch add syscall sendto --in /usr/bin/app shows what a
program sends, and a capture shows the packets.
Capturing the packets
Every disk has tcpdump in the machine itself, at /usr/sbin/tcpdump, so a
capture needs nothing in the containers’ images. Write the capture under
/.machine/output/keep, and the run keeps it as its output, named
/output/keep/db.pcap.
machine containers lists what a capture needs: each container’s ADDRESS,
and its LINK, the machine’s interface at the other end of the
container’s own:
1 | machine containers app |
1 | SERVICE CONTAINER ID STATE IMAGE ADDRESS LINK LIMITS |
To capture one container’s packets, capture on its LINK:
1 | machine exec app start -- tcpdump --immediate-mode -U -i veth45c3e2e -w /.machine/output/keep/db.pcap |
--immediate-mode and -U write each packet as it is captured: without
them, the packets tcpdump has not written yet when it stops are lost. The
stop waits for tcpdump to exit, so the file is whole before it is read.
Open db.pcap in Wireshark or read it with tcpdump on this computer.
On its link each packet db sends or receives appears once, as an Ethernet
frame, ARP included. Broadcasts from the other containers appear too, since
the bridge sends them to every link. A packet a fault on db dropped or still
holds is not there: the capture sees what db’s faults let through, and what
reaches db. The LINK changes when docker starts the container again, and
so do addresses from run to run, so read them in the run you capture.
--net db runs tcpdump on db’s own network instead, so its eth0 is db’s
link, and the name stays the same across restarts:
1 | machine exec app start --net db -- tcpdump --immediate-mode -U -i eth0 -w /.machine/output/keep/db.pcap |
It captures the same packets as a capture on the LINK. For example, with
db’s ICMP lost by loss db 100% --proto icmp, both show the pings reaching
db and none of db’s replies.
To capture every container at once, use -i any and filter by ADDRESS:
1 | machine exec app start -- tcpdump --immediate-mode -U -i any -w /.machine/output/keep/all.pcap host 172.18.0.2 |
With -i any, each packet between two containers appears twice: as it
arrives from the sender’s link, P, and as it leaves toward the receiver’s,
Out. The file records each packet’s interface by an index that means
nothing on this computer, so filter by address rather than by interface.
A replay writes the same capture, byte for byte, with loss, delay and clock
jumps in effect. The timestamps are the machine’s date: clock jump of the
whole machine moves them, and a container’s offset does not. A link between
containers carries TCP segments larger than its MTU, since the kernel
segments them only where a real interface needs it.
Finding the address and the link by hand
machine containers reads both from the machine; they can be read by hand
as well. Docker knows each container’s address by the container’s name:
1 | machine exec app run -- docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}} {{end}}' compose-db-1 # 172.18.0.2 |
A container’s eth0 is one end of a pair, and the container’s iflink is
the number of the machine’s interface at the other end:
1 | machine exec app run --container db -- cat /sys/class/net/eth0/iflink # 6 |
Faults from inside a container: iptables and tc
A test that injects its own network faults runs unchanged in a machine. A
container started with cap_add: [NET_ADMIN] can change its own firewall and
traffic control with iptables, ip6tables and tc, as long as its image
has those programs:
1 | services: |
The first command makes db drop everything api sends it, and the second removes the rule, so api reaches db again:
1 | machine exec app run --container db --user root -- iptables -A INPUT -s api -j DROP |
With -j REJECT in place of -j DROP, api’s connections to db are refused
at once instead of timing out. iptables resolves api to its address when
the rule is added, so the rule no longer matches an api that is recreated
at another address.
The machine’s kernel has both nftables and the legacy tables, so either kind
of iptables works. Debian’s and Ubuntu’s iptables use nftables by default,
and an image switched to iptables-legacy works as it is. Both kinds have the
filter, nat, mangle and raw tables, for IPv4 and IPv6, with the common
targets, such as DROP, REJECT, MARK and MASQUERADE, and the common
matches, such as multiport, conntrack, limit, statistic, string and
u32. tc has the prio, tbf, netem and plug disciplines and the
u32 filter. A run keeps the kernel it was created with, so a run created
before November 24, 2026 has the legacy tables alone.
A container’s rules act on the packets that container sends and receives.
The machine’s bridge between containers does not pass packets through
iptables, so a rule written on the machine itself, outside every container,
does not filter traffic between containers. A container’s rules are part of
the run like everything else the container does, so a replay applies them at
the same moments and drops the same packets.
machine net puts its faults on the root tc discipline of each container’s
link. On one container, use either the container’s own tc or machine net,
not both. A container’s own root discipline, such as
tc qdisc add dev eth0 root netem delay 10ms, replaces the one machine net
put there, and the container’s machine net faults stop acting. The listing
then warns that they are not in effect, and
machine net app apply db applies them
again, which also removes the container’s own discipline:
1 | db compose-db-1 - - delay 100ms - 0 0 0 |
machine net needs no change to the images and no NET_ADMIN, and it logs
every decision it makes. A fault the test makes itself is still the better
choice when the test already has one.
What a network fault misses
Traffic inside one container, over its loopback, has no link to fault.
DNS between containers is answered on each container’s loopback, so no fault reaches it. Point the container’s resolver at an address that does not answer, and its lookups time out; write the file back to restore them:
1
2machine exec app run --container api --user root -- sh -c 'cp /etc/resolv.conf /etc/resolv.keep; echo nameserver 192.0.2.1 > /etc/resolv.conf'
machine exec app run --container api --user root -- sh -c 'cat /etc/resolv.keep > /etc/resolv.conf'Address resolution follows the whole link’s faults unless a match names
--proto arp: a match of another protocol takes IP packets alone. Withloss db 30%, db’s ARP requests are lost too, and right after a start, with nothing resolved yet, db can take seconds to reach a peer.A fault is on what a container sends. To fault what
dbreceives, put the fault on each container that sends to it, with--to db. To slow both directions between two containers, put a fault on each, aspartitiondoes.A container on another’s network, with
network_mode: service:db,hostornone, has no link of its own, and a fault on it is refused. Put the fault on the container whose network it uses.A process outside every container, on the machine itself, sends on no container’s link. What it sends to a container takes no fault, and only the container’s replies do.
A rate is per sender. Three containers each limited to 1mbit toward
dbgivedb3 megabits a second, not one link of 1 megabit.A damaged packet rarely reaches the program.
corruptchanges one bit anywhere in a packet’s frame, and the IP, TCP and UDP checksums drop nearly every damaged packet; TCP then sends it again. A bit in the Ethernet addresses is not caught by a checksum. No fault hands a damaged payload to the program.Losing exactly the Nth packet, bursts of loss, and delays other than a uniform jitter: a fault decides each packet on its own, by its chance.
IPv4 alone. Ports and SYNs are matched in packets without IP options, which Docker’s networks send.
The path’s MTU stays as Docker sets it.
Loss of TCP is per unit the kernel hands the link, not per wire segment. Between containers the kernel sends a large TCP write as one packet many times the MTU, segmented only where a real interface needs it: for example, most are 8244 bytes.
loss 1%drops 1% of those units, each as many segments as it holds, and TCP sends the whole unit again. The log’slenshows each unit’s size.