{"record":{"id":"d1cc309763aa2e68","repo":"vectordotdev/vector","slug":"failed-to-bind-to-listener-socket-at-path-err","errorCode":null,"errorMessage":"Failed to bind to listener socket at path: {}. Err: {}","messagePattern":"Failed to bind to listener socket at path: (.+?)\\. Err: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"src/sources/util/unix_stream.rs","lineNumber":54,"sourceCode":"/// Passing in different functions for `decoder` and `handle_events` can allow\n/// for different source-specific logic (such as decoding syslog messages in the\n/// syslog source).\npub fn build_unix_stream_source<D, F, E>(\n    listen_path: PathBuf,\n    socket_file_mode: Option<u32>,\n    decoder: D,\n    handle_events: impl Fn(&mut [Event], Option<Bytes>) + Clone + Send + Sync + 'static,\n    shutdown: ShutdownSignal,\n    out: SourceSender,\n) -> crate::Result<Source>\nwhere\n    D: tokio_util::codec::Decoder<Item = (F, usize), Error = E> + Clone + Send + 'static,\n    E: StreamDecodingError + std::fmt::Display + Send + From<std::io::Error>,\n    F: Into<SmallVec<[Event; 1]>> + Send,\n{\n    Ok(Box::pin(async move {\n        let listener = UnixListener::bind(&listen_path).unwrap_or_else(|e| {\n            panic!(\n                \"Failed to bind to listener socket at path: {}. Err: {}\",\n                listen_path.to_string_lossy(),\n                e\n            )\n        });\n        info!(message = \"Listening.\", path = ?listen_path, r#type = \"unix\");\n\n        change_socket_permissions(&listen_path, socket_file_mode)\n            .expect(\"Failed to set socket permissions\");\n\n        let bytes_received = register!(BytesReceived::from(Protocol::UNIX));\n\n        let connection_open = OpenGauge::new();\n        let stream = UnixListenerStream::new(listener).take_until(shutdown.clone());\n        tokio::pin!(stream);\n        while let Some(socket) = stream.next().await {\n            let socket = match socket {\n                Err(error) => {","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/vectordotdev/vector/blob/3708c39b12a93212ed8b8d7510b4cc7769cb5864/src/sources/util/unix_stream.rs#L36-L72","documentation":"Unix-stream sources (socket sources configured with a filesystem path) bind a tokio UnixListener at startup and panic if bind() fails, printing the path and the io::Error. Because the bind happens inside the spawned source future, the failure is fatal for the run: the process aborts instead of silently running without the source.","triggerScenarios":"A stale socket file already exists at the path (previous Vector killed uncleanly); the parent directory does not exist or lacks write permission for the Vector user; the path exceeds the OS unix-socket address limit (~108 chars for sun_path on Linux).","commonSituations":"Restarting after a crash without cleanup; running under a different user than the socket directory owner; a second Vector instance already bound to the same path; long confined paths in containers and /run vs /var/run symlink confusion.","solutions":["Remove the stale socket before start: rm -f <path> (systemd ExecStartPre=-/usr/bin/rm -f <path> works well)","Shorten the path and ensure its directory exists and is writable by the Vector user","Ensure exactly one Vector instance uses the path: lsof <path> or ss -x | grep <path>","If a supervisor restarts Vector, add pre-stop cleanup so stop/start cycles don't leak the socket"],"exampleFix":"# before (systemd unit)\n[Service]\nExecStart=/usr/bin/vector --config /etc/vector/vector.toml\n\n# after\n[Service]\nExecStartPre=-/usr/bin/rm -f /var/run/vector/vector.sock\nExecStart=/usr/bin/vector --config /etc/vector/vector.toml","handlingStrategy":"validation","validationCode":"# Pre-start check (shell):\nif [ -S \"$SOCK\" ]; then rm -f \"$SOCK\" || exit 1; fi\nmkdir -p \"$(dirname \"$SOCK\")\" && [ -w \"$(dirname \"$SOCK\")\" ] || exit 1\n\n// Rust (embedding): probe before the source runs\nif listen_path.exists() { std::fs::remove_file(&listen_path)?; }\nstd::fs::create_dir_all(listen_path.parent().unwrap())?;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clean socket paths in ExecStartPre/pre-stop hooks","Keep socket paths short and under a directory owned by the Vector user","Monitor for duplicate Vector processes binding the same socket"],"tags":["rust","vector","unix-socket","source","bind","panic","filesystem"],"backgroundTag":"unix-socket-bind-failed","analyzedSha":"3708c39b12a93212ed8b8d7510b4cc7769cb5864","analyzedAt":"2026-08-20T07:02:18.786Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}