vectordotdev/vector · error

Encountered a connection-time error during runtime: {:?}

Error message

Encountered a connection-time error during runtime: {:?}

What it means

The websocket source classifies errors into connect-time (ConnectTimeout, InitialMessageTimeout, ConnectionClosedPrematurely) and runtime variants; only runtime errors should surface from the main receive loop. The loop matches connect-time variants with unreachable! because by construction they can only occur inside connect()/reconnect(), never from a live connection's next().

Source

Thrown at src/sources/websocket/source.rs:152

                                std::io::ErrorKind::TimedOut,
                                "Pong timeout"
                            ))
                        });
                        emit!(WebSocketConnectionShutdown);
                        return Err(error);
                    }
                    WebSocketSourceError::Tungstenite { source: ws_err } => {
                        if is_closed(&ws_err) {
                            emit!(WebSocketConnectionShutdown);
                        }
                        error!(message = "WebSocket connection error.", error = %ws_err);
                    }
                    // These errors should only happen during `connect` or `reconnect`,
                    // not in the main loop's result.
                    WebSocketSourceError::ConnectTimeout
                    | WebSocketSourceError::InitialMessageTimeout
                    | WebSocketSourceError::ConnectionClosedPrematurely => {
                        unreachable!(
                            "Encountered a connection-time error during runtime: {:?}",
                            error
                        );
                    }
                }
                if self
                    .reconnect(&mut out, &mut ws_sink, &mut ws_source)
                    .await
                    .is_err()
                {
                    break;
                }
            }
        }
        Ok(())
    }

    async fn handle_message(

View on GitHub (pinned to 3708c39b12)

Solutions

  1. Upgrade Vector so the bundled tungstenite version matches the tested classification
  2. Point the source at a compliant endpoint (test the same URL with websocat/wscat) and rule out intermediaries mangling the session
  3. Reproduce with debug logging around reconnects and report the error sequence
  4. If a proxy is involved, adjust websocket keepalive/proxy buffering settings for that route
Defensive patterns

Strategy: try-catch

Try / catch

// Source task panic = source failure; reconnect at the pipeline level with bounded retries:
loop {
    if let Err(je) = tokio::spawn(websocket::run(cfg.clone(), shutdown.clone())).await {
        if je.is_panic() {
            tokio::time::sleep(backoff.next()).await; // then continue; break after N tries
            continue;
        }
    }
    break;
}

Prevention

When it happens

Trigger: An error classified as connect-time being returned by the live-connection stream - tokio-tungstenite surfacing a handshake/timeout error mid-session after a version change, or the source's error wrapper misclassifying variants when reconnect bookkeeping changes.

Common situations: Upgrades of tokio-tungstenite/tungstenite altering when errors are produced; non-conforming WS servers or intermediaries (proxies, load balancers) producing handshake-shaped errors mid-stream; custom error-classification patches.

Related errors


AI-assisted analysis of vectordotdev/vector@3708c39b12 (2026-08-20). Data as JSON: /api/errors/c56ebfe22d234654. Report an issue: GitHub.