ErrorKind::WouldBlock
RustINFOCriticalI/O
Operation would block
Quick Answer
Register the socket with an event loop (tokio, mio) and retry when ready.
What this means
A non-blocking I/O operation cannot proceed immediately. Equivalent to EAGAIN/EWOULDBLOCK.
Why it happens
- 1Reading from a non-blocking socket with no data available
- 2Writing to a non-blocking socket with a full buffer
Fix
Use async I/O instead
Use async I/O instead
// With tokio:
use tokio::io::AsyncReadExt;
let mut stream = tokio::net::TcpStream::connect("host:80").await?;
let mut buf = [0u8; 1024];
stream.read(&mut buf).await?; // never returns WouldBlockWhy this works
Async runtimes handle WouldBlock internally via OS readiness notifications.
Code examples
Non-blocking setrust
stream.set_nonblocking(true)?;
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