{"record":{"id":"a815e32f5584241a","repo":"xai-org/grok-build","slug":"bind-e","errorCode":null,"errorMessage":"bind {}: {e}","messagePattern":"bind (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-grok-diag-server/src/lib.rs","lineNumber":412,"sourceCode":"\n/// Bind the listener and spawn the server task.\n/// Binding happens before this returns, so a bind failure surfaces synchronously.\n/// `log_file` is the daemon log served by `/logs` (`None` means `/logs` is 404).\npub async fn serve(\n    listener: DiagListener,\n    handle: DiagHandle,\n    log_file: Option<PathBuf>,\n) -> anyhow::Result<BoundDiag> {\n    let ctx = DiagContext {\n        handle,\n        log_file: log_file.map(Arc::new),\n    };\n    match listener {\n        #[cfg(unix)]\n        DiagListener::Unix(path) => {\n            let _ = fs::remove_file(&path);\n            let listener =\n                UnixListener::bind(&path).map_err(|e| anyhow!(\"bind {}: {e}\", path.display()))?;\n            use std::os::unix::fs::PermissionsExt as _;\n            if let Err(e) = fs::set_permissions(&path, fs::Permissions::from_mode(0o600)) {\n                tracing::warn!(\n                    path = %path.display(),\n                    error = %e,\n                    \"failed to restrict diagnostics socket permissions\"\n                );\n            }\n            let task = tokio::spawn(async move {\n                if let Err(e) = axum::serve(listener, router(ctx)).await {\n                    tracing::warn!(error = %e, \"diagnostics server exited\");\n                }\n            });\n            Ok(BoundDiag {\n                addr: format!(\"unix:{}\", path.display()),\n                port: None,\n                task,\n            })","sourceCodeStart":394,"sourceCodeEnd":430,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-diag-server/src/lib.rs#L394-L430","documentation":"serve() failed to bind the diagnostics Unix domain socket at the given path. Any existing socket file is removed first, so this error comes from the OS refusing the bind (unwritable/nonexistent parent directory, path too long, or a race where another process re-created the socket). The diag server never starts.","triggerScenarios":"DiagListener::Unix(path) where the parent directory does not exist or is not writable, the socket path exceeds the ~104-char Unix socket limit, or another process concurrently holds the path as a live socket.","commonSituations":"XDG_RUNTIME_DIR or temp dir cleaned up/never created; running under a sandbox/container without write access to the socket directory; very long cache paths exceeding sockaddr_un limits.","solutions":["Verify the socket's parent directory exists and is writable by the current user; create it if needed","Shorten the socket path (e.g. use a shorter tmp dir) if it exceeds the Unix socket path limit","Check no other live process owns the socket path (ss -x | grep <name>) and stop it","Run in an environment (container/sandbox) that permits creating Unix sockets in the chosen directory"],"exampleFix":"// before\nlet path = \"/very/long/cache/path/with/many/components/grok-diag.sock\";\n// after\nlet path = std::env::temp_dir().join(\"grok-diag.sock\"); // short, guaranteed-writable path","handlingStrategy":"validation","validationCode":"let dir = path.parent().expect(\"socket path has parent\");\nif !dir.exists() {\n    std::fs::create_dir_all(dir)?;\n}\nif path.as_os_str().len() > 100 {\n    return Err(anyhow!(\"socket path too long: {}\", path.display()));\n}","typeGuard":"fn socket_path_ok(path: &std::path::Path) -> bool {\n    path.parent().map(|d| d.is_dir()).unwrap_or(false)\n        && path.as_os_str().len() <= 100\n}","tryCatchPattern":"match serve(ctx, DiagListener::Unix(path)).await {\n    Ok(h) => h,\n    Err(e) if e.to_string().starts_with(\"bind \") => {\n        eprintln!(\"diag unix socket bind failed: {e:#}; check dir permissions/path length\");\n        return Err(e);\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Ensure the socket directory exists and is writable before serve()","Keep Unix socket paths short (use temp_dir or XDG_RUNTIME_DIR)","Check for other processes bound to the same socket path (ss -x)","Account for sandbox/container filesystem restrictions"],"tags":["unix-socket","bind","filesystem","permissions","diagnostics"],"backgroundTag":"unix-socket-bind-failed","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}