vectordotdev/vector · error

Can't set receive buffer size on connection that has not…

Error message

Can't set receive buffer size on connection that has not been accepted yet.

What it means

`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.

Solutions

  1. Call `set_receive_buffer_bytes` only after the connection is accepted and stored.
  2. Ensure the accept future is awaited before socket tuning.
  3. Configure receive buffer via the listener config so it is applied at accept time.

Example fix

// before
conn.set_receive_buffer_bytes(1 << 20)?; // conn not accepted yet

// after
let conn = listener.accept().await?; // stream now present
conn.set_receive_buffer_bytes(1 << 20)?;
Defensive patterns

Strategy: try-catch

Validate before calling

if conn.get_ref().is_none() {
    return Err(std::io::Error::new(std::io::ErrorKind::NotConnected, "not accepted"));
}

Type guard

fn has_stream(conn: &IncomingConnection) -> bool { conn.get_ref().is_some() }

Try / catch

if let Err(e) = conn.set_receive_buffer_bytes(bytes) {
    if e.kind() == std::io::ErrorKind::NotConnected { /* skip tuning */ }
}

Prevention

When it happens

Trigger: Calling `set_receive_buffer_bytes` on the connection wrapper before the accept path has populated the inner stream.

Common situations: Same race as keepalive: buffer-size tuning invoked before awaiting accept, or on the listener rather than the accepted connection.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of vectordotdev/vector@bdb87aeaa4 (2026-09-16). Data as JSON: /api/errors/cc47c001654ef96c. Report an issue: GitHub.

Appendix: source

Thrown at lib/vector-core/src/tls/incoming.rs:332

            io::Error::new(
                io::ErrorKind::NotConnected,
                "Can't set keepalive on connection that has not been accepted yet.",
            )
        })?;

        if let Some(time_secs) = keepalive.time_secs {
            let config =
                socket2::TcpKeepalive::new().with_time(std::time::Duration::from_secs(time_secs));

            tcp::set_keepalive(stream, &config)?;
        }

        Ok(())
    }

    pub fn set_receive_buffer_bytes(&mut self, bytes: usize) -> std::io::Result<()> {
        let stream = self.get_ref().ok_or_else(|| {
            io::Error::new(
                io::ErrorKind::NotConnected,
                "Can't set receive buffer size on connection that has not been accepted yet.",
            )
        })?;

        tcp::set_receive_buffer_size(stream, bytes)
    }

    fn poll_io<T, F>(self: Pin<&mut Self>, cx: &mut Context, poll_fn: F) -> Poll<io::Result<T>>
    where
        F: FnOnce(Pin<&mut MaybeTlsStream<TcpStream>>, &mut Context) -> Poll<io::Result<T>>,
    {
        let this = self.get_mut();
        loop {
            return match &mut this.state {
                StreamState::Accepted(stream) => poll_fn(Pin::new(stream), cx),
                StreamState::Accepting(fut) => match std::task::ready!(fut.as_mut().poll(cx)) {
                    Ok(stream) => {

View on GitHub (pinned to bdb87aeaa4)