{"record":{"id":"cc47c001654ef96c","repo":"vectordotdev/vector","slug":"can-t-set-receive-buffer-size-on-connection-that-has-not","errorCode":null,"errorMessage":"Can't set receive buffer size on connection that has not been accepted yet.","messagePattern":"Can't set receive buffer size on connection that has not been accepted yet\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/vector-core/src/tls/incoming.rs","lineNumber":332,"sourceCode":"            io::Error::new(\n                io::ErrorKind::NotConnected,\n                \"Can't set keepalive on connection that has not been accepted yet.\",\n            )\n        })?;\n\n        if let Some(time_secs) = keepalive.time_secs {\n            let config =\n                socket2::TcpKeepalive::new().with_time(std::time::Duration::from_secs(time_secs));\n\n            tcp::set_keepalive(stream, &config)?;\n        }\n\n        Ok(())\n    }\n\n    pub fn set_receive_buffer_bytes(&mut self, bytes: usize) -> std::io::Result<()> {\n        let stream = self.get_ref().ok_or_else(|| {\n            io::Error::new(\n                io::ErrorKind::NotConnected,\n                \"Can't set receive buffer size on connection that has not been accepted yet.\",\n            )\n        })?;\n\n        tcp::set_receive_buffer_size(stream, bytes)\n    }\n\n    fn poll_io<T, F>(self: Pin<&mut Self>, cx: &mut Context, poll_fn: F) -> Poll<io::Result<T>>\n    where\n        F: FnOnce(Pin<&mut MaybeTlsStream<TcpStream>>, &mut Context) -> Poll<io::Result<T>>,\n    {\n        let this = self.get_mut();\n        loop {\n            return match &mut this.state {\n                StreamState::Accepted(stream) => poll_fn(Pin::new(stream), cx),\n                StreamState::Accepting(fut) => match std::task::ready!(fut.as_mut().poll(cx)) {\n                    Ok(stream) => {","sourceCodeStart":314,"sourceCodeEnd":350,"githubUrl":"https://github.com/vectordotdev/vector/blob/bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013/lib/vector-core/src/tls/incoming.rs#L314-L350","documentation":"`set_receive_buffer_bytes` on the incoming TLS connection wrapper requires the accepted TCP stream; if `get_ref()` returns None (connection not yet accepted/stored), it returns `Err(NotConnected)` with this message instead of silently skipping the SO_RCVBUF adjustment.","triggerScenarios":"Calling `set_receive_buffer_bytes` on the connection wrapper before the accept path has populated the inner stream.","commonSituations":"Same race as keepalive: buffer-size tuning invoked before awaiting accept, or on the listener rather than the accepted connection.","solutions":["Call `set_receive_buffer_bytes` only after the connection is accepted and stored.","Ensure the accept future is awaited before socket tuning.","Configure receive buffer via the listener config so it is applied at accept time."],"exampleFix":"// before\nconn.set_receive_buffer_bytes(1 << 20)?; // conn not accepted yet\n\n// after\nlet conn = listener.accept().await?; // stream now present\nconn.set_receive_buffer_bytes(1 << 20)?;","handlingStrategy":"try-catch","validationCode":"if conn.get_ref().is_none() {\n    return Err(std::io::Error::new(std::io::ErrorKind::NotConnected, \"not accepted\"));\n}","typeGuard":"fn has_stream(conn: &IncomingConnection) -> bool { conn.get_ref().is_some() }","tryCatchPattern":"if let Err(e) = conn.set_receive_buffer_bytes(bytes) {\n    if e.kind() == std::io::ErrorKind::NotConnected { /* skip tuning */ }\n}","preventionTips":["Sequence accept -> tune -> serve strictly in one task.","Prefer configuring receive buffer size in listener config so it's applied post-accept."],"tags":["network","tcp","tls","socket-buffer"],"backgroundTag":"invalid-state-transition","analyzedSha":"bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013","analyzedAt":"2026-09-16T02:53:35.741Z","contentChangedAt":"2026-09-16T02:53:35.741Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}