{"record":{"id":"f0416a4d6acb6943","repo":"facebook/flow","slug":"socket-timeout","errorCode":null,"errorMessage":"socket timeout","messagePattern":"socket timeout","errorType":"exception","errorClass":"std::io::Error","httpStatus":null,"severity":"error","filePath":"rust_port/crates/flow_common_socket/src/socket.rs","lineNumber":401,"sourceCode":"    }\n}\n\n#[cfg(windows)]\nfn wait_for_ready(\n    timeout: Option<Duration>,\n    ready: impl std::future::Future<Output = io::Result<()>>,\n) -> io::Result<()> {\n    match timeout {\n        None => flow_tokio_runtime::block_on(ready),\n        Some(timeout) => {\n            // `tokio::time::timeout` constructs a `Sleep` that registers with\n            // the reactor at construction time, so it must be created inside\n            // the runtime context, not before `block_on`.\n            match flow_tokio_runtime::block_on(\n                async move { tokio::time::timeout(timeout, ready).await },\n            ) {\n                Ok(result) => result,\n                Err(_) => Err(io::Error::new(io::ErrorKind::TimedOut, \"socket timeout\")),\n            }\n        }\n    }\n}\n\nimpl Read for SocketStream {\n    fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {\n        if buf.is_empty() {\n            return Ok(0);\n        }\n        #[cfg(unix)]\n        {\n            self.socket.read(buf)\n        }\n        #[cfg(windows)]\n        {\n            loop {\n                let result = match &*self.pipe {","sourceCodeStart":383,"sourceCodeEnd":419,"githubUrl":"https://github.com/facebook/flow/blob/f88ac94bcf6992f5d5a158854d94613ebb92c6e6/rust_port/crates/flow_common_socket/src/socket.rs#L383-L419","documentation":"wait_ready wraps a socket readiness future (connect or read/write readiness) in tokio::time::timeout inside block_on, honoring the timeout the caller set via SocketStream::set_read_timeout / set_write_timeout. If the underlying operation does not become ready within that duration, it returns ErrorKind::TimedOut \"socket timeout\" — the peer neither progressed nor closed within your deadline.","triggerScenarios":"A read or write on a SocketStream after set_read_timeout/set_write_timeout(Some(d)) where the server sends nothing and keeps the connection open longer than d; or a connect/readiness wait exceeding the configured timeout.","commonSituations":"A hung or SIGSTOP-ed Flow server that leaves the socket open but never replies; a very large query legitimately slower than a locally-tuned timeout; loaded CI machines turning normally-fast requests into timeouts.","solutions":["Raise the read/write timeout to comfortably cover the slowest legitimate request (large project checks can take seconds).","Check the server's health (logs, CPU, whether it is stopped under a debugger) — a silent-but-open peer is usually a hung server.","Retry the request on a fresh connection; Flow client queries are idempotent, so re-issuing after a timeout is safe.","If the operation legitimately exceeds the timeout, shrink the payload or split the query."],"exampleFix":"// before: tuned for instant local replies\nstream.set_read_timeout(Some(Duration::from_millis(100)))?;\n\n// after: budget for large queries and loaded machines\nstream.set_read_timeout(Some(Duration::from_secs(30)))?;","handlingStrategy":"retry","validationCode":null,"typeGuard":"fn is_socket_timeout(e: &std::io::Error) -> bool {\n    e.kind() == std::io::ErrorKind::TimedOut && e.to_string().contains(\"socket timeout\")\n}","tryCatchPattern":"Match ErrorKind::TimedOut on stream ops: re-issue the request once on a fresh connection (Flow queries are idempotent), then surface 'server unresponsive' if it repeats. Other error kinds (UnexpectedEof, BrokenPipe) mean the connection died — reconnect without retrying blindly.","preventionTips":["Set read/write timeouts to at least several times your p99 request duration.","Watch server health (heartbeat/log activity) and reconnect on repeated timeouts.","Make callers timeout-aware: treat TimedOut as retryable, not as a data error."],"tags":["socket","timeout","read-write","rust"],"backgroundTag":"socket-timeout","analyzedSha":"f88ac94bcf6992f5d5a158854d94613ebb92c6e6","analyzedAt":"2026-08-20T10:41:37.992Z","schemaVersion":2},"datasetVersion":"2026-08-23T11:17:13.642Z"}