moonpool ~
GitHub →
$ techniques

Network faults

Cut a link, clog it, close a connection: the faults that TCP code sees.

The problem

On a real network, a link stops for some seconds, a connection closes in the middle of a request, a peer accepts bytes and never answers. Each of these is rare on one machine and frequent on a thousand. A test on a laptop network almost never sees them, so the code that handles them is the code with no test.

The technique

moonpool simulates the network at the level of TCP connections, as FoundationDB does: the faults are the ones that application code sees. There are 9 families. Each family is one NetworkFault variant and one bit of the fault mask. A seed draws when each fault starts and how long it stays. With ChaosMode::Swarm, each seed also switches off a random set of families, because a lot of a few faults finds more bugs than a little of each.

Each fault the simulator injects is an event of the run (sim_fault, with its kind). The workload does not know about it. It sees only late, lost or refused messages.

The live run

This seed has every network family on: two partitions, clogs and a black hole. Switch some families off, then run the same seed again. The table counts the faults of each kind in the two runs. With other families, the same seed makes other choices, so it is another run. It is still one run per seed and per set of families: run it again and you get the same events.

network fault families of this run

The code

The site's engine turns on network chaos with one entry of the builder:

if chaos.network {
    out.push(Chaos::Network(mode));
}

The switches above set a mask. A family that is not in the mask never fires, whatever the seed draws:

let builder = match &config.network_faults {
    Some(names) => builder.network_fault_mask(
        families(NETWORK_FAULTS, names)
            .unwrap_or_default()
            .into_iter()
            .fold(NetworkFaultMask::none(), NetworkFaultMask::with),
    ),
    None => builder,
};

The server and the client of the register do not change. They use ctx.network(), and the simulated network decides what each connection does.

In the Guide

All the techniques