{"record":{"id":"bfd7e7749310680d","repo":"vectordotdev/vector","slug":"failed-to-bind-to-datagram-socket","errorCode":null,"errorMessage":"Failed to bind to datagram socket","messagePattern":"Failed to bind to datagram socket","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/sources/util/unix_datagram.rs","lineNumber":42,"sourceCode":"        util::{change_socket_permissions, unix::UNNAMED_SOCKET_HOST},\n    },\n};\n\n/// Returns a `Source` object corresponding to a Unix domain datagram socket.\n/// 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_datagram_source(\n    listen_path: PathBuf,\n    socket_file_mode: Option<u32>,\n    max_length: usize,\n    decoder: Decoder,\n    handle_events: impl Fn(&mut [Event], Option<Bytes>) + Clone + Send + Sync + 'static,\n    shutdown: ShutdownSignal,\n    out: SourceSender,\n) -> crate::Result<Source> {\n    Ok(Box::pin(async move {\n        let socket = UnixDatagram::bind(&listen_path).expect(\"Failed to bind to datagram socket\");\n        info!(message = \"Listening.\", path = ?listen_path, r#type = \"unix_datagram\");\n\n        change_socket_permissions(&listen_path, socket_file_mode)\n            .expect(\"Failed to set socket permissions\");\n\n        let result = listen(socket, max_length, decoder, shutdown, handle_events, out).await;\n\n        // Delete socket file.\n        if let Err(error) = remove_file(&listen_path) {\n            emit!(UnixSocketFileDeleteError {\n                path: &listen_path,\n                error\n            });\n        }\n\n        result\n    }))\n}","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/vectordotdev/vector/blob/3708c39b12a93212ed8b8d7510b4cc7769cb5864/src/sources/util/unix_datagram.rs#L24-L60","documentation":"`UnixDatagram::bind(&listen_path)` failed and this `expect(\"Failed to bind to datagram socket\")` panics the source task. Typical OS causes: the socket path already exists (stale socket file from an unclean shutdown), the path exceeds the ~107-byte unix socket address limit (sun_path), the parent directory does not exist, or the process lacks write permission on the directory.","triggerScenarios":"Starting a unix_datagram source (e.g. syslog over unix datagram) while socket_path already exists as a file; socket_path longer than 107 bytes; parent dir missing or not writable by the Vector user.","commonSituations":"Vector killed with SIGKILL (OOM, kill -9) leaving the socket file behind; deeply nested socket paths; running as non-root with socket_path under /run without systemd socket activation; two Vector instances configured with the same path.","solutions":["Remove the stale socket file before start (systemd `ExecStartPre=/usr/bin/rm -f <path>` or an init script rm)","Shorten socket_path to well under 108 bytes total","Ensure the parent directory exists and is writable by Vector's user","Ensure only one Vector instance binds the same socket path"],"exampleFix":"# before\n[Service]\nExecStart=/usr/bin/vector --config /etc/vector/vector.yaml\n# after\n[Service]\nExecStartPre=/usr/bin/rm -f /var/run/vector/syslog.sock\nExecStart=/usr/bin/vector --config /etc/vector/vector.yaml","handlingStrategy":"validation","validationCode":"# shell: pre-start checks for a unix_datagram socket\nSOCKET=/var/run/vector/syslog.sock\n[ -e \"$SOCKET\" ] && rm -f \"$SOCKET\"\n[ ${#SOCKET} -lt 108 ] || { echo \"socket path too long\"; exit 1; }\nmkdir -p \"$(dirname \"$SOCKET\")\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use systemd ExecStartPre=/usr/bin/rm -f <socket> on units that own unix sockets","Keep socket paths short (/run/vector/x.sock)","Ensure exactly one Vector instance per socket path","Prefer systemd socket activation for non-root setups"],"tags":["unix-socket","datagram","bind","syslog","panic"],"backgroundTag":"unix-socket-bind-failed","analyzedSha":"3708c39b12a93212ed8b8d7510b4cc7769cb5864","analyzedAt":"2026-08-20T07:02:18.786Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}