{"record":{"id":"2c898fba1e60918c","repo":"facebook/flow","slug":"cannot-get-hostname","errorCode":null,"errorMessage":"Cannot get hostname","messagePattern":"Cannot get hostname","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"rust_port/crates/flow_config/src/flowconfig.rs","lineNumber":3124,"sourceCode":"\nfn parse_strict(config: &mut FlowConfig, lines: &[(u32, String)]) -> Result<(), Error> {\n    let lines = trim_numbered_lines(lines);\n    let strict_mode =\n        StrictModeSettings::of_lines(&lines).map_err(|(line, msg)| Error(line, msg))?;\n    config.strict_mode = strict_mode;\n    Ok(())\n}\n\n// Rollouts are based on randomness, but we want it to be stable from run to run. So we seed our\n// pseudo random number generator with\n//\n// 1. The hostname\n// 2. The user\n// 3. The name of the rollout\nfn calculate_rollout_percentage(rollout_name: &str) -> u32 {\n    use std::hash::Hash;\n    use std::hash::Hasher;\n    let host_name = hostname::get().expect(\"Cannot get hostname\");\n    let mut hasher = DefaultHasher::new();\n    host_name.hash(&mut hasher);\n    #[cfg(unix)]\n    {\n        unsafe { libc::getuid() }.hash(&mut hasher);\n    }\n    rollout_name.hash(&mut hasher);\n    (hasher.finish() % 100) as u32\n}\n\n// The optional rollout section has 0 or more lines. Each line defines a single rollout. For example\n//\n// [rollouts]\n//\n// testA=40% on, 60% off\n// testB=50% blue, 20% yellow, 30% pink\n//\n// The first line defines a rollout named \"testA\" with two groups.","sourceCodeStart":3106,"sourceCodeEnd":3142,"githubUrl":"https://github.com/facebook/flow/blob/5c865861998a8ccb7dbc82b0c1f511e9ef60c3d9/rust_port/crates/flow_config/src/flowconfig.rs#L3106-L3142","documentation":"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.","triggerScenarios":"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.","commonSituations":"Containers with unusual hostname setups; VMs/images where /etc/hostname or the kernel hostname was set to invalid data; minimal environments after botched provisioning.","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."],"exampleFix":"// before\nlet host_name = hostname::get().expect(\"Cannot get hostname\");\n\n// after\nlet host_name = hostname::get()\n    .map(|h| h.to_string_lossy().into_owned())\n    .unwrap_or_else(|_| \"unknown-host\".to_string());","handlingStrategy":"validation","validationCode":"// Check the hostname is retrievable and UTF-8 before running flow commands\nfn hostname_ok() -> bool {\n    hostname::get().map(|h| h.to_str().is_some()).unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":"let host_name = hostname::get()\n    .map(|h| h.to_string_lossy().into_owned())\n    .unwrap_or_else(|_| \"unknown-host\".to_string());","preventionTips":["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."],"tags":["hostname","flowconfig","rollout","environment"],"backgroundTag":"hostname-lookup-failed","analyzedSha":"5c865861998a8ccb7dbc82b0c1f511e9ef60c3d9","analyzedAt":"2026-08-20T10:41:37.992Z","contentChangedAt":"2026-08-20T10:41:37.992Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}