Repository navigation
feat(moonpool-sim): in-flight faults and end-to-end TCP flow control - #202
Merged
Merged
Conversation
A chunk that left the send queue used to travel *inside* its scheduled
`DataDelivery` event: once the write latency had been sampled, nothing
could touch it, and `handle_data_delivery` landed it without asking
whether a partition had gone up in the meantime. A response written at
t=0 with 100ms of latency crossed a partition that started at t=50ms,
and so did an in-flight FIN. Only the queued (not yet drained) chunk
stalled.
The bytes now live in the engine, in a per-connection `in_flight` queue
owned by the sender (`InFlight { seq, deliver_at, payload }`, payload a
data chunk or the FIN), and the scheduler event is a wake-up that names
an item (`NetworkEvent::Delivery { connection_id, seq }`) rather than
carrying it. A delivery lands only from the head of the flight, only
once its `deliver_at` has passed, and never while the direction is held,
so a stale event is a no-op and faults are judged at landing:
- every partition insertion (pair, send-wide, receive-wide, the random
strategies) freezes the flight of each direction it cuts
(`in_flight_held_since`); nothing is put on the wire under a cut, and a
FIN queued under one is frozen from that instant;
- every heal (deadline, `restore_partition`, recovery mode) thaws the
flight by re-timing each item by exactly the time the direction spent
cut and re-scheduling its event, so a cut of D delays every byte it
caught by D, the stream stays FIFO (the floor for the next send moves
with it), and no randomness is drawn — the latencies already sampled
are reused;
- a black hole opened while a chunk is in flight swallows it at landing;
- an abort discards the flight with the queue.
The FIN is an in-flight item behind the data, so it can neither overtake
the last bytes nor cross a partition ahead of them. `NetworkEvent` no
longer carries payload and is `Copy`.
Tests (`tests/network/in_flight.rs`, fixed 10ms latency): partition after
the send with exact landing time, heal by hand with the remaining flight
time, directionality, send-wide and receive-wide cuts, FIFO across the
cut boundary, an in-flight FIN, a close issued under the cut, recovery
mode healing with zero RNG draws, and a mid-flight black hole. The book's
partition section documents the four-stage byte lifecycle and the
freeze/thaw rule.
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VXnMuFCFvF66WYwXUyXDJz
…direction
The 64 KiB send buffer only bounded the *local* queue: `ProcessSendBuffer`
released its capacity the moment a chunk left the queue, so a writer could
run forever as long as the engine kept moving bytes into the scheduler and
then into an unbounded receive buffer. A reader that stopped reading never
backed its writer up, which is not TCP backpressure at all.
Each direction now has one `SendWindow` (`NetworkConfiguration::
tcp_send_window_bytes`, `SimulationBuilder::tcp_send_window_bytes`, default
64 KiB as before) with the invariant
outstanding = queued + in_flight + unread_at_peer (+ vanished)
outstanding <= capacity
Credit is acquired in `buffer_send`, when `poll_write` accepts the bytes,
and released only when the peer's `poll_read` hands them to its
application, byte for byte — a 137-byte partial read returns 137 bytes.
Moving bytes from the queue onto the wire or from the wire into the
receive buffer releases nothing. A write still accepts `min(len,
available)` and parks only at zero; a parked writer is woken by the peer's
read (outside the world lock, like every other waiter).
Faults: a partition returns no credit (delay is not consumption) and the
thawed bytes are released by the read that follows the heal; a black hole
never returns it, so a black-holed direction accepts a window's worth —
the small RPC that must time out at the application still goes in — and
then blocks instead of absorbing data forever; an abort discards the
queue, the flight and the unread bytes and wakes a parked writer to the
error; a peer that closes or shuts its receive side with bytes unread
frees them (the kernel acknowledged what it throws away), and bytes it
discards on arrival are released too, so no writer is ever parked on
credits nothing can return. The FIN sits behind outstanding data and
cannot overtake it.
`SendWindow::acquire` and `::release` assert rather than saturate: an
over-acquire or a double release panics with the counts, and unit tests
pin both.
Determinism: a `Poll::Pending` on a full window, the wake after a read,
and every move between the three places consume no simulation
randomness; the campaign test below runs under `check_determinism`.
Tests (`tests/flow_control.rs`): the central case (writer parks at
64 KiB even with every byte in the receive buffer; a 4 KiB read wakes it
and the next write accepts exactly 4 KiB), partial-read credit, a
partition returning nothing until the read, black-hole backpressure,
abort and peer-close waking a parked writer, FIN behind data, and a
scripted run under 50ms latency, small partial reads and a temporary cut
asserting the accounting identity after every event. The campaign — a
streamer into a slow reader over a 4 KiB window with latency, partial
writes and reads and two scripted cuts — proves the block/resume cycle
on every seed with the determinism canary green.
`SimWorld::send_buffer_capacity/used` and `available_send_buffer` become
`send_window_bytes`, `outstanding_send_bytes` and `available_send_bytes`;
`queued_send_bytes`, `in_flight_bytes` and `unread_bytes` expose the
three places for tests. The book gets a Flow control section, and the
scope chapter no longer lists TCP backpressure as unmodelled.
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VXnMuFCFvF66WYwXUyXDJz
This was referenced Sep 5, 2026
Closed
PierreZ
pushed a commit
that referenced
this pull request
Oct 4, 2026
… paros Checked against paros's call sites (paros#176, #202): - paros's driver hooks (`BuggifyHooks`) live inside the provider-generic driver and never hold a `SimContext`, so `crash_self` could not reach the kill-during-sync location #202 wants. `SimContext::self_crash()` returns a `SelfCrash` handle (`Clone + Send + Sync + 'static`) whose `crash(kind, delay)` schedules the same kill; `crash_self` is now a shorthand for it. - A scripted injector aiming `corrupt_bytes` at one journal record needs the record's bytes, e.g. `JournalAtlas::scan` on the crashed node's disk. `FaultContext::storage(ip)` returns a provider scoped to that process's disk. paros at 29b23e3 builds unchanged (paros-sim, parosd, tests) against this branch through a local [patch]. Part of #297, #296 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017Pv7ppXLHvimhFfSqMapGy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two related changes to the simulated network, one commit each.
1. Faults reach traffic already in flight
Before. A chunk that left the send queue travelled inside its scheduled
DataDelivery { data }event. Once the write latency was sampled, nothing could touch it:handle_data_deliverychecked the receiver's close flags and the black hole, never a partition. So a response written at t=0 with 100ms of latency crossed a partition that started at t=50ms, and so did an in-flight FIN. Only the chunk still sitting in the queue stalled.After. The bytes live in the engine, in a per-connection
in_flightqueue owned by the sender (InFlight { seq, deliver_at, payload: Data | Fin }). The scheduler event is a payload-free wake-up,NetworkEvent::Delivery { connection_id, seq }. A delivery lands only from the head of the flight, only oncedeliver_athas passed, and never while the direction is held, so faults are judged at landing:restore_partition, recovery mode) re-times each frozen item by exactly the time the direction spent cut and re-schedules it, so a cut of D delays every byte it caught by D, the stream stays FIFO, and no randomness is drawn;Semantics stay the documented FDB-style one: a partition stalls the stream and never punches a hole in it.
2. End-to-end TCP flow control
Before. The 64 KiB send buffer only bounded the local queue.
ProcessSendBufferreleased capacity the moment a chunk left the queue, so a writer could run forever as long as the engine kept moving bytes into the scheduler and then into an unbounded receive buffer. A reader that stopped reading never backed its writer up.After. Each direction has one
SendWindow(NetworkConfiguration::tcp_send_window_bytes,SimulationBuilder::tcp_send_window_bytes, default 64 KiB as before):Credit is acquired when
poll_writeaccepts bytes and released only when the peer'spoll_readhands them to its application, byte for byte (a 137-byte partial read returns 137 bytes). Moving bytes between the queue, the wire and the receive buffer releases nothing. A partition returns no credit; a black hole never returns it, so a black-holed direction accepts a window's worth (the small RPC that must time out at the application still goes in) and then blocks; an abort discards everything and wakes a parked writer to the error; a peer that closes with bytes unread frees them.SendWindow::acquire/releaseassert instead of saturating, so an over-acquire or double release panics.Backpressure is entropy-neutral: a
Poll::Pendingon a full window, the wake after a read, and every move between the three places consume no simulation randomness. The campaign test runs undercheck_determinism.Tests
tests/network/in_flight.rs(fixed 10ms latency): partition after the send with exact landing time, heal by hand, directionality, send-wide and receive-wide cuts, FIFO across the cut boundary, in-flight FIN, close under the cut, recovery mode with zero RNG draws, mid-flight black hole.tests/flow_control.rs: writer parks at 64 KiB even with every byte in the receive buffer and a 4 KiB read lets exactly 4 KiB through; partial-read credit; partition returns nothing until the read; black-hole backpressure; abort and peer close wake a parked writer; FIN behind data; a scripted run under 50ms latency, small partial reads and a temporary cut asserting the accounting identity after every event; and theSimulationBuildercampaign (streamer into a slow reader, 4 KiB window, partial I/O, latency, two scripted cuts) with the determinism canary green on every seed.SendWindowunit tests pin the double-release and over-acquire panics.API changes
NetworkEvent::DataDelivery/FinDeliverybecomeNetworkEvent::Delivery { connection_id, seq };NetworkEventis nowCopy.SimWorld::send_buffer_capacity/send_buffer_used/available_send_bufferbecomesend_window_bytes/outstanding_send_bytes/available_send_bytes;queued_send_bytes,in_flight_bytes,unread_bytes,is_in_flight_heldadded.NetworkConfiguration::tcp_send_window_bytes(+DEFAULT_TCP_SEND_WINDOW_BYTES) andSimulationBuilder::tcp_send_window_bytes.Book: partition section documents the four-stage byte lifecycle and the freeze/thaw rule; new Flow control section; scope chapter no longer lists TCP backpressure as unmodelled; event-trace and config appendix updated.
Validation
cargo fmt,cargo clippy --workspace --all-targets -- -D warnings,clippy -p moonpool-sim --no-default-features --all-targets -- -D warnings,cargo check --target wasm32-unknown-unknown -p moonpool-sim --no-default-features,cargo nextest run --workspace(770 passed),mdbook build book/.Known gaps, tracked separately
🤖 Generated with Claude Code
https://claude.ai/code/session_01VXnMuFCFvF66WYwXUyXDJz