Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelog.d/24300_systemd_socket_activation.fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Fix collection from systemd sockets.

Systemd sockets are passed in blocking mode, but tokio expects them to be in non-blocking mode.
Therefore, always set sockets from systemd to non-blocking.

authors: j-c-fuchs aagor
9 changes: 6 additions & 3 deletions src/sources/util/net/tcp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,12 @@ pub async fn try_bind_tcp_listener(
match addr {
SocketListenAddr::SocketAddr(addr) => tls.bind(&addr).await.map_err(Into::into),
SocketListenAddr::SystemdFd(offset) => match listenfd.take_tcp_listener(offset)? {
Some(listener) => TcpListener::from_std(listener)
.map(Into::into)
.map_err(Into::into),
Some(listener) => {
listener.set_nonblocking(true)?;
TcpListener::from_std(listener)
.map(Into::into)
.map_err(Into::into)
}
None => {
Err(io::Error::new(io::ErrorKind::AddrInUse, "systemd fd already consumed").into())
}
Expand Down
5 changes: 4 additions & 1 deletion src/sources/util/net/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ pub async fn try_bind_udp_socket(
match addr {
SocketListenAddr::SocketAddr(addr) => UdpSocket::bind(&addr).await,
SocketListenAddr::SystemdFd(offset) => match listenfd.take_udp_socket(offset)? {
Some(socket) => UdpSocket::from_std(socket),
Some(socket) => {
socket.set_nonblocking(true)?;
UdpSocket::from_std(socket)
}
None => Err(io::Error::new(
io::ErrorKind::AddrInUse,
"systemd fd already consumed",
Expand Down
Loading