facebook/flow · error
Cannot get hostname
Error message
Cannot get hostname
What it means
Rollout bucketing in flowconfig parsing seeds a hasher with hostname + uid + rollout name via `hostname::get().expect("Cannot get hostname")`. `hostname::get()` performs an OS gethostname call; it errors when the syscall fails (rare; broken container/namespace setup) or when the resulting name is not usable as configured, and the expect kills every flow command during config parsing since the rollout percentage is computed eagerly.
Solutions
- Set a valid hostname and retry: `hostnamectl set-hostname myhost` (or docker `--hostname`, k8s hostname field), or `sudo sysctl kernel.hostname=myhost`.
- Verify the current hostname is sane: `cat /proc/sys/kernel/hostname` should print valid UTF-8.
- Remove or rename the `[rollout]` entries in .flowconfig if rollout gating is not needed, so this code path is skipped.
- As a code fix, use `to_string_lossy()` or a fixed fallback ("unknown-host") instead of expect.
Example fix
// before
let host_name = hostname::get().expect("Cannot get hostname");
// after
let host_name = hostname::get()
.map(|h| h.to_string_lossy().into_owned())
.unwrap_or_else(|_| "unknown-host".to_string()); Defensive patterns
Strategy: validation
Validate before calling
// Check the hostname is retrievable and UTF-8 before running flow commands
fn hostname_ok() -> bool {
hostname::get().map(|h| h.to_str().is_some()).unwrap_or(false)
} Try / catch
let host_name = hostname::get()
.map(|h| h.to_string_lossy().into_owned())
.unwrap_or_else(|_| "unknown-host".to_string()); Prevention
- Set a valid hostname in images/containers (docker --hostname, k8s hostname, hostnamectl).
- Verify `cat /proc/sys/kernel/hostname` prints valid UTF-8 after provisioning.
- Drop unused [rollout] sections from .flowconfig if rollout gating is unnecessary.
When it happens
Trigger: A hostname containing invalid bytes (provisioning tools setting raw bytes via sysctl); a container with a broken/uninitialized hostname; hosts where gethostname fails under a restrictive sandbox.
Common situations: Containers with unusual hostname setups; VMs/images where /etc/hostname or the kernel hostname was set to invalid data; minimal environments after botched provisioning.
Related errors
- failed to get current directory
- Failed to query mergebase: unable to find vcs
- failed to read executable at
- flow-dot-js wasm requires crypto.getRandomValues
- init failed
AI-assisted analysis of facebook/flow@21c11b2ead (2026-08-20).
Data as JSON: /api/errors/2c898fba1e60918c.
Report an issue: GitHub.
Appendix: source
Thrown at rust_port/crates/flow_config/src/flowconfig.rs:3136
fn parse_strict(config: &mut FlowConfig, lines: &[(u32, String)]) -> Result<(), Error> {
let lines = trim_numbered_lines(lines);
let strict_mode =
StrictModeSettings::of_lines(&lines).map_err(|(line, msg)| Error(line, msg))?;
config.strict_mode = strict_mode;
Ok(())
}
// Rollouts are based on randomness, but we want it to be stable from run to run. So we seed our
// pseudo random number generator with
//
// 1. The hostname
// 2. The user
// 3. The name of the rollout
fn calculate_rollout_percentage(rollout_name: &str) -> u32 {
use std::hash::Hash;
use std::hash::Hasher;
let host_name = hostname::get().expect("Cannot get hostname");
let mut hasher = DefaultHasher::new();
host_name.hash(&mut hasher);
#[cfg(unix)]
{
unsafe { libc::getuid() }.hash(&mut hasher);
}
rollout_name.hash(&mut hasher);
(hasher.finish() % 100) as u32
}
// The optional rollout section has 0 or more lines. Each line defines a single rollout. For example
//
// [rollouts]
//
// testA=40% on, 60% off
// testB=50% blue, 20% yellow, 30% pink
//
// The first line defines a rollout named "testA" with two groups.View on GitHub (pinned to 21c11b2ead)