Will It Blend? - TCP Streams
| src | ||
| .gitignore | ||
| Cargo.lock | ||
| Cargo.toml | ||
| LICENSE | ||
| mise.toml | ||
| README.md | ||
| screenshot.png | ||
Will It Blend
This script demonstrates the risk of interleaving writes when cloning
TcpStream handles across threads, re:
this discussion in the Servo Zulip.
It spawns 3 threads:
- 2 TCP clients, each of which sends predictable chunks of bytes over a shared
connection with
TcpStream::write_all() - 1 TCP listener, which tests whether messages arrive contiguously or scrambled together
Messages consist of the range 0x00..=0xff, repeated to fill the desired
message size. The TCP listener prints a warning if it detects any byte received
out of order.
Usage
cargo run --release <message size in bytes>
Results
A message size of 1024 bytes can be sufficient to trigger fragmentation when running an optimized build. Results from debug builds are hit-or-miss depending on the host system: they may have no issues with fragmentation regardless of message size, or they may encounter issues at closer to 4096 bytes.
