{"record":{"id":"914a212ce4cc6ad5","repo":"facebook/flow","slug":"timed-out-connecting-to-named-pipe","errorCode":null,"errorMessage":"timed out connecting to named pipe","messagePattern":"timed out connecting to named pipe","errorType":"exception","errorClass":"std::io::Error","httpStatus":null,"severity":"error","filePath":"rust_port/crates/flow_common_socket/src/socket.rs","lineNumber":313,"sourceCode":"            };\n            loop {\n                let result = flow_tokio_runtime::block_on(async {\n                    tokio::net::windows::named_pipe::ClientOptions::new().open(pipe_name)\n                });\n                match result {\n                    Ok(client) => {\n                        return Ok(Self {\n                            pipe: Arc::new(NamedPipeStream::Client(client)),\n                            read_timeout: Arc::new(Mutex::new(None)),\n                            write_timeout: Arc::new(Mutex::new(None)),\n                        });\n                    }\n                    Err(e)\n                        if e.kind() == io::ErrorKind::NotFound\n                            || e.raw_os_error() == Some(ERROR_PIPE_BUSY) =>\n                    {\n                        if std::time::Instant::now() >= deadline {\n                            return Err(io::Error::new(\n                                io::ErrorKind::TimedOut,\n                                \"timed out connecting to named pipe\",\n                            ));\n                        }\n                        std::thread::sleep(Duration::from_millis(10));\n                    }\n                    Err(e) => return Err(e),\n                }\n            }\n        }\n    }\n\n    pub fn try_clone(&self) -> io::Result<Self> {\n        #[cfg(unix)]\n        {\n            Ok(Self {\n                socket: self.socket.try_clone()?,\n            })","sourceCodeStart":295,"sourceCodeEnd":331,"githubUrl":"https://github.com/facebook/flow/blob/f88ac94bcf6992f5d5a158854d94613ebb92c6e6/rust_port/crates/flow_common_socket/src/socket.rs#L295-L331","documentation":"On Windows, SocketStream::connect opens the server's named pipe (\\\\.\\pipe\\...) in a retry loop: tokio's ClientOptions::open returns NotFound while the pipe does not exist yet, or ERROR_PIPE_BUSY (231) when all pipe instances are in use, and the loop sleeps 10 ms and retries until a deadline. When the deadline passes you get ErrorKind::TimedOut \"timed out connecting to named pipe\" — the pipe never became connectable in the window you allowed.","triggerScenarios":"Calling SocketStream::connect(&Addr::NamedPipe(..), timeout) against a server that has not created the pipe yet (still initializing or crashed at startup), a server whose pipe instances are all busy, a wrong pipe name, or with a timeout too small for a cold server start.","commonSituations":"Server binary crashing during startup (check its stderr); antivirus or slow disks delaying process start; many concurrent clients saturating the pipe instances; connecting with a stale pipe name after the server reconfigured.","solutions":["Verify the Flow server is actually running and listening on the exact pipe name the client passes.","Increase the timeout passed to SocketStream::connect — cold starts (AV scans, debug builds) routinely need seconds, not milliseconds.","If the server crashed at startup, read its logs/stderr, fix the crash, restart it, then connect.","Throttle concurrent client connections or retry later when connections report busy."],"exampleFix":"// before: 500ms is too small for a cold server start\nlet stream = SocketStream::connect(&addr, Duration::from_millis(500))?;\n\n// after: budget for cold start; on TimedOut verify the server and retry once\nlet stream = match SocketStream::connect(&addr, Duration::from_secs(5)) {\n    Ok(s) => s,\n    Err(e) if e.kind() == io::ErrorKind::TimedOut => {\n        ensure_server_running(&addr)?; // check/restart the server first\n        SocketStream::connect(&addr, Duration::from_secs(5))?\n    }\n    Err(e) => return Err(e),\n};","handlingStrategy":"retry","validationCode":null,"typeGuard":"fn is_pipe_connect_timeout(e: &std::io::Error) -> bool {\n    e.kind() == std::io::ErrorKind::TimedOut && e.to_string().contains(\"named pipe\")\n}","tryCatchPattern":"Branch on ErrorKind::TimedOut: verify/restart the server, then retry the connect once with backoff. Propagate NotFound and other kinds immediately — they indicate a wrong pipe name, not slowness.","preventionTips":["Wait for the server's readiness signal (socket/lock file present) before connecting clients.","Size connect timeouts for cold starts: AV scans and debug builds need seconds.","Cap concurrent client connections so pipe instances are not all busy."],"tags":["windows","named-pipe","timeout","connect","rust"],"backgroundTag":"connection-timeout","analyzedSha":"f88ac94bcf6992f5d5a158854d94613ebb92c6e6","analyzedAt":"2026-08-20T10:41:37.992Z","schemaVersion":2},"datasetVersion":"2026-08-23T11:17:13.642Z"}