{"record":{"id":"665b69585c20479f","repo":"neondatabase/neon","slug":"bad-value-in-pidfile-pid","errorCode":null,"errorMessage":"bad value in pidfile '{pid}'","messagePattern":"bad value in pidfile '(.+?)'","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"libs/utils/src/pid_file.rs","lineNumber":163,"sourceCode":"            content,\n        } => {\n            // XXX the read races with the write in claim_pid_file_for_pid().\n            // But pids are smaller than a page, so the kernel page cache will lock for us.\n            // The only problem is that we might get the old contents here.\n            // Can only fix that by implementing some scheme that downgrades the\n            // exclusive lock to shared lock in claim_pid_file_for_pid().\n            PidFileRead::LockedByOtherProcess(parse_pidfile_content(&content)?)\n        }\n    };\n    Ok(ret)\n}\n\nfn parse_pidfile_content(content: &str) -> anyhow::Result<Pid> {\n    let pid: i32 = content\n        .parse()\n        .map_err(|_| anyhow::anyhow!(\"parse pidfile content to PID\"))?;\n    if pid < 1 {\n        anyhow::bail!(\"bad value in pidfile '{pid}'\");\n    }\n    Ok(Pid::from_raw(pid))\n}\n","sourceCodeStart":145,"sourceCodeEnd":167,"githubUrl":"https://github.com/neondatabase/neon/blob/8f60b04da47ffefe0e52bda2440134b42874eb75/libs/utils/src/pid_file.rs#L145-L167","documentation":"parse_pidfile_content first parses the pidfile as i32 and then rejects values below 1. A parseable but impossible PID (0 or negative) cannot name a process, so reading the pidfile fails with the offending value included in the message.","triggerScenarios":"A pidfile containing '0', '-1', or another value < 1, e.g. written by a tool that zero-initializes files before forking or by corrupted state.","commonSituations":"Zero-filled files after an unclean shutdown; monitoring tooling writing placeholder zeros; manual edits.","solutions":["cat the pidfile to confirm the invalid value","If the file is stale (no flock holder), remove it while the service is stopped and restart","Audit what wrote the invalid value so it does not recur"],"exampleFix":"# before\n$ cat /var/lib/neon.pid\n0\n# after: with the service stopped, remove the stale file and restart\n# rm /var/lib/neon.pid\nsystemctl start neon","handlingStrategy":"validation","validationCode":"fn pidfile_content_is_valid(path: &std::path::Path) -> bool {\n    std::fs::read_to_string(path)\n        .ok()\n        .and_then(|c| c.trim().parse::<i32>().ok())\n        .is_some_and(|pid| pid >= 1)\n}","typeGuard":"fn is_bad_pid_value_error(err: &anyhow::Error) -> bool {\n    err.to_string().contains(\"bad value in pidfile\")\n}","tryCatchPattern":"match pid_file::read(&path) {\n    Err(e) if e.to_string().contains(\"bad value in pidfile\") => {\n        // the message embeds the value; if the file is stale (no flock holder), remove it while stopped\n    }\n    other => other?,\n}","preventionTips":["Do not zero-initialize pidfiles before handing them to the service","Check pidfile validity in startup scripts","Investigate any tool that writes values < 1 into the pidfile path"],"tags":["rust","pidfile","filesystem","parsing"],"backgroundTag":"invalid-pidfile","analyzedSha":"8f60b04da47ffefe0e52bda2440134b42874eb75","analyzedAt":"2026-08-16T23:39:28.135Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}