ducaale/xh · error

Connection timeout is too big

Error message

Connection timeout is too big

What it means

Validation guard in Timeout's FromStr impl: the --connection-timeout value is finite and non-negative but numerically too large to be represented as a Duration — it equals or exceeds Duration::MAX.as_secs_f64(), or is infinite. Duration::from_secs_f64 would panic on such input, so it is rejected up front. Fires when the user passes an absurdly large timeout like 1e30.

Solutions

  1. Use a large but finite value below Duration::MAX (e.g. --timeout=1e9)
  2. Remove the timeout to rely on defaults for effectively-unbounded waiting
  3. Validate computed timeout values against Duration::MAX before passing

Example fix

# before
http --timeout=inf GET example.org
# after
http --timeout=3600 GET example.org
Defensive patterns

Strategy: validation

Validate before calling

// validate the magnitude before invoking
let v: f64 = timeout_str.parse()?;
if v.is_infinite() || v >= std::time::Duration::MAX.as_secs_f64() {
    return Err("timeout too large; use a finite value");
}

Type guard

fn timeout_fits_duration(s: &str) -> bool {
    s.parse::<f64>().map(|v| v.is_finite() && v < std::time::Duration::MAX.as_secs_f64()).unwrap_or(false)
}

Try / catch

let out = Command::new("http").args(["--timeout", &timeout_str, "GET", url]).output()?;
if !out.status.success() && String::from_utf8_lossy(&out.stderr).contains("timeout is too big") {
    eprintln!("use a finite timeout, e.g. --timeout=3600");
}

Prevention

When it happens

Trigger: Passing --timeout=inf, --timeout=1e400 (parses to inf), or a finite value >= ~1.8e19 seconds (Duration::MAX).

Common situations: Using 'inf' to mean 'wait forever'; passing enormous sentinel values from scripts.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of ducaale/xh@2404aceecc (2026-09-13). Data as JSON: /api/errors/1d6b984279d6ae2e. Report an issue: GitHub.

Appendix: source

Thrown at src/cli.rs:1206

#[derive(Debug, Clone)]
pub struct Timeout(Duration);

impl Timeout {
    pub fn as_duration(&self) -> Option<Duration> {
        Some(self.0).filter(|t| !t.is_zero())
    }
}

impl FromStr for Timeout {
    type Err = anyhow::Error;

    fn from_str(sec: &str) -> anyhow::Result<Timeout> {
        match f64::from_str(sec) {
            Ok(s) if !s.is_nan() => {
                if s.is_sign_negative() {
                    Err(anyhow!("Connection timeout is negative"))
                } else if s >= Duration::MAX.as_secs_f64() || s.is_infinite() {
                    Err(anyhow!("Connection timeout is too big"))
                } else {
                    Ok(Timeout(Duration::from_secs_f64(s)))
                }
            }
            _ => Err(anyhow!("Connection timeout is not a valid number")),
        }
    }
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Proxy {
    Http(Url),
    Https(Url),
    All(Url),
}

impl FromStr for Proxy {
    type Err = anyhow::Error;

View on GitHub (pinned to 2404aceecc)