neondatabase/neon · error

Invalid host

Error message

Invalid host

What it means

After URL parsing and the structural checks, the host component itself is unusable: url.host() is None (input was port-only like ':5555'), or it is a domain failing hostname_validator::is_valid (leading hyphen '-collector.host.tld', underscores, overlong labels), or another non-IP host form the match does not accept. Only valid domains, IPv4 and IPv6 literals pass.

Source

Thrown at compute_tools/src/rsyslog.rs:121

    })?;

    let is_valid = url.scheme() == "http"
        && url.path() == "/"
        && url.query().is_none()
        && url.fragment().is_none()
        && url.username() == ""
        && url.password().is_none();

    if !is_valid {
        return Err(anyhow!(
            "Invalid address format {remote_endpoint}, expected host:port"
        ));
    }
    let host = match url.host() {
        Some(Host::Domain(h)) if hostname_validator::is_valid(h) => h.to_string(),
        Some(Host::Ipv4(ip4)) => ip4.to_string(),
        Some(Host::Ipv6(ip6)) => ip6.to_string(),
        _ => return Err(anyhow!("Invalid host")),
    };
    let port = url
        .port()
        .ok_or_else(|| anyhow!("Invalid port in {remote_endpoint}"))?;

    Ok((host, port, tls))
}

fn generate_audit_rsyslog_config(
    log_directory: String,
    endpoint_id: &str,
    project_id: &str,
    remote_syslog_host: &str,
    remote_syslog_port: u16,
    remote_syslog_tls: &str,
) -> String {
    format!(
        include_str!("config_template/compute_audit_rsyslog_template.conf"),

View on GitHub (pinned to 8f60b04da4)

Solutions

  1. Use a syntactically valid hostname (alphanumeric plus hyphens, no leading/trailing hyphen) or an IP literal
  2. If the real host has underscores or exotic characters, reference it by IP address instead
  3. Ensure the host part is non-empty when a port is present

Example fix

# before
AUDIT_LOGGING_ENDPOINT=-collector.host.tld:5555

# after
AUDIT_LOGGING_ENDPOINT=collector.host.tld:5555
Defensive patterns

Strategy: validation

Validate before calling

// check hostname validity before configure_audit_rsyslog
if !hostname_validator::is_valid(host) {
    bail!("audit endpoint host {host:?} is not a valid hostname; use a valid domain or an IP literal");
}

Type guard

fn is_valid_host(host: &str) -> bool {
    hostname_validator::is_valid(host)
        || host.parse::<std::net::Ipv4Addr>().is_ok()
        || host.parse::<std::net::Ipv6Addr>().is_ok()
}

Try / catch

let host = match url.host() {
    Some(Host::Domain(h)) if hostname_validator::is_valid(h) => h.to_string(),
    Some(Host::Ipv4(ip4)) => ip4.to_string(),
    Some(Host::Ipv6(ip6)) => ip6.to_string(),
    _ => return Err(anyhow!("Invalid host")),
};

Prevention

When it happens

Trigger: Input ':5555' (empty host), '-collector.host.tld:5555' (invalid hostname), hosts with underscores or other characters forbidden by RFC hostname rules.

Common situations: Internal hostnames containing underscores (common in k8s service names hand-written by users); typos adding leading dashes; empty host values paired with a port.

Related errors


AI-assisted analysis of neondatabase/neon@8f60b04da4 (2026-08-16). Data as JSON: /api/errors/a5901b082a9ebe0e. Report an issue: GitHub.