{"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":"critical","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/bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013/src/sources/util/unix_datagram.rs#L24-L60","documentation":"The Unix datagram source binds a UnixDatagram socket to the configured `path` inside the spawned source task and .expect()s success. If the bind fails, the process panics with \"Failed to bind to datagram socket\" — typically because the path is unusable: another socket exists, the directory is missing, or permissions deny creation.","triggerScenarios":"path points to a directory that does not exist or is not writable; a stale socket file from a previous unclean shutdown occupies the path; another Vector instance is already bound; the path exceeds unix socket path length limits.","commonSituations":"Restarting Vector after SIGKILL leaves the socket file behind; container filesystems with read-only paths; running as non-root while path is in /var/run; duplicated configs binding the same socket path.","solutions":["Remove any stale socket file at the configured path before starting Vector","Ensure the parent directory exists and Vector's user has write permission","Stop the other process (or previous Vector instance) already bound to that path","Change the configured socket path to a writable, shorter location"],"exampleFix":"// before\nrm: not done; /var/run/vector.sock is stale\n// after\nrm -f /var/run/vector.sock && vector --config vector.yaml","handlingStrategy":"validation","validationCode":"SOCK=/var/run/vector.sock; rm -f \"$SOCK\"; test -d \"$(dirname \"$SOCK\")\" && test -w \"$(dirname \"$SOCK\")\" && echo ok","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Delete stale socket files on startup/shutdown (systemd ExecStartPre=/bin/rm -f)","Ensure the socket's parent directory exists and is writable by Vector's user","Avoid two Vector instances binding the same path"],"tags":["rust","panic","unix-socket","bind"],"backgroundTag":"address-already-in-use","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"}