{"record":{"id":"b3305dbc5441aa01","repo":"vectordotdev/vector","slug":"systemd-fd-already-consumed","errorCode":null,"errorMessage":"systemd fd already consumed","messagePattern":"systemd fd already consumed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/sources/util/net/tcp/mod.rs","lineNumber":68,"sourceCode":"\npub async fn try_bind_tcp_listener(\n    addr: SocketListenAddr,\n    mut listenfd: ListenFd,\n    tls: &MaybeTlsSettings,\n    tls_reloader: Option<TlsAcceptorReloader>,\n    allowlist: Option<Vec<IpNet>>,\n) -> crate::Result<MaybeTlsListener> {\n    match addr {\n        SocketListenAddr::SocketAddr(addr) => tls\n            .bind_reloadable(&addr, tls_reloader)\n            .await\n            .map_err(Into::into),\n        SocketListenAddr::SystemdFd(offset) => match listenfd.take_tcp_listener(offset)? {\n            Some(listener) => TcpListener::from_std(listener)\n                .map(Into::into)\n                .map_err(Into::into),\n            None => {\n                Err(io::Error::new(io::ErrorKind::AddrInUse, \"systemd fd already consumed\").into())\n            }\n        },\n    }\n    .map(|listener| listener.with_allowlist(allowlist))\n}\n\n#[derive(Clone, Copy, Eq, PartialEq)]\npub enum TcpSourceAck {\n    Ack,\n    Error,\n    Reject,\n}\n\npub trait TcpSourceAcker {\n    fn build_ack(self, ack: TcpSourceAck) -> Option<Bytes>;\n}\n\npub struct TcpNullAcker;","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/vectordotdev/vector/blob/3708c39b12a93212ed8b8d7510b4cc7769cb5864/src/sources/util/net/tcp/mod.rs#L50-L86","documentation":"Runtime error from `build_ts_tcp_listener` in src/sources/util/net/tcp/mod.rs. When a socket address is `SocketListenAddr::SystemdFd(offset)`, Vector asks `listenfd` (the systemd socket-activation fds) for the listener at that offset. `take_tcp_listener` returning `None` means no TCP listener exists at that offset — the fd index is out of range or the fd was already taken — and Vector surfaces it as `io::Error` (kind `AddrInUse`, message \"systemd fd already consumed\").","triggerScenarios":"Configuring `address = \"systemd\"` / `use_systemd_fd = N` while: running Vector outside systemd (no `LISTEN_FDS` passed), the systemd socket unit passing fewer fds than the configured offset (offsets are 0-based over the inherited fds), a second listener re-taking an fd already consumed (e.g. after config reload rebinding), or the systemd unit not actually enabled for socket activation.","commonSituations":"Debugging a systemd-socket-activated Vector manually (foreground, no systemd) while the config still points at inherited fds; `.socket` units whose `ListenStream=` entries don't line up 1:1 with the Vector sources' fd offsets.","solutions":["Run Vector under systemd with the socket unit started so the fds are actually inherited (`systemctl start vector.socket vector.service`)","Align the number and order of `ListenStream=` entries with the configured fd offsets (fd 3 = offset 0, fd 4 = offset 1, ...)","Ensure each configured listener uses a distinct fd — an fd can only be taken once; check reload paths that rebind","When not using socket activation, bind a concrete address (`address = \"0.0.0.0:9000\"`) instead of `systemd`"],"exampleFix":"# before\n[sources.in]\ntype = \"socket\"\naddress = \"systemd\" # fails when run outside systemd\n\n# after (manual/dev run)\n[sources.in]\ntype = \"socket\"\naddress = \"0.0.0.0:9000\"","handlingStrategy":"validation","validationCode":"// Before using SocketListenAddr::SystemdFd(offset), confirm fds were inherited\nfn systemd_fd_count() -> Option<usize> {\n    let pid_ok = std::env::var(\"LISTEN_PID\").ok()?.parse::<u32>().ok()? == std::process::id();\n    let fds = std::env::var(\"LISTEN_FDS\").ok()?.parse::<usize>().ok()?;\n    pid_ok.then_some(fds)\n}\n// use: systemd_fd_count().is_some_and(|n| n > offset)","typeGuard":null,"tryCatchPattern":"match build_tcp_listener(addr, listenfd, tls, reloader).await {\n    Err(e) if e.to_string().contains(\"systemd fd already consumed\") => {\n        // fd offset out of range or already taken: fix the .socket unit / offsets, don't retry\n    }\n    other => other,\n}","preventionTips":["Run Vector under systemd with the .socket unit started when binding to \"systemd\"","Keep ListenStream= entries in the unit in exact 1:1 order with configured fd offsets (offset 0 = fd 3)","Use a distinct fd per listener; never re-take an fd across reloads","When debugging outside systemd, temporarily bind a concrete host:port"],"tags":["rust","systemd","socket-activation","tcp","startup","vector-source"],"backgroundTag":"systemd-socket-activation-fd-missing","analyzedSha":"3708c39b12a93212ed8b8d7510b4cc7769cb5864","analyzedAt":"2026-08-20T07:02:18.786Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}