rust network_error ai_generated true

hyper::Error(Io, Kind(ConnectionReset))

ID: rust/rust-hyper-connection-reset

Also available as: JSON · Markdown
80%Fix Rate
83%Confidence
50Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1 active

Root Cause

The remote peer reset the TCP connection. Usually caused by timeouts, server restarts, or load balancer disconnects.

generic

Workarounds

  1. 88% success Implement retry logic with exponential backoff
    use tokio::time::{sleep, Duration};
    for attempt in 0..3 {
        match client.request(req.clone()).await {
            Ok(resp) => return Ok(resp),
            Err(e) if is_connection_reset(&e) => {
                sleep(Duration::from_millis(100 * 2u64.pow(attempt))).await;
            }
            Err(e) => return Err(e),
        }
    }

    Sources: https://docs.rs/hyper/latest/hyper/

  2. 85% success Use connection pooling with proper idle timeout configuration
    use hyper::client::HttpConnector;
    let client = hyper::Client::builder()
        .pool_idle_timeout(Duration::from_secs(30))
        .build::<_, hyper::Body>(HttpConnector::new());

    Sources: https://docs.rs/hyper/latest/hyper/client/struct.Builder.html

Dead Ends

Common approaches that don't work:

  1. Increase TCP keepalive to very long intervals 60% fail

    Extremely long keepalives don't prevent resets from server-side timeouts or restarts

Error Chain

Leads to:
Preceded by:
Frequently confused with: