ErrorKind::ConnectionReset
RustERRORNotableNetwork
Connection reset by peer
Quick Answer
Reconnect and implement retry logic; the peer may have crashed or restarted.
What this means
The remote side abruptly closed the connection by sending a TCP RST packet.
Why it happens
- 1Server crashed mid-request
- 2Network appliance forcibly closed idle connections
- 3Mismatched TLS versions
Fix
Detect and reconnect
Detect and reconnect
use std::io::{Read, ErrorKind};
fn read_data(stream: &mut impl Read) -> std::io::Result<Vec<u8>> {
let mut buf = vec![0u8; 1024];
match stream.read(&mut buf) {
Err(e) if e.kind() == ErrorKind::ConnectionReset => Err(e),
r => r.map(|n| buf[..n].to_vec()),
}
}Why this works
Surface ConnectionReset so the caller can re-establish the connection.
Code examples
Triggerrust
// Server calls shutdown(SHUT_RDWR) while client reads
Same error in other languages
Sources
Official documentation ↗
Rust std::io
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev