Skip to content

Commit 82d879a

Browse files
authored
Make the socket received from systemd non-blocking (#1081)
This PR set a socket received from systemd to non-blocking so it can be used properly with Tokio.
1 parent 74fe582 commit 82d879a

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

src/process.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,16 @@ impl Process {
102102
pub fn get_listen_fd(&self) -> Result<Option<TcpListener>, Failed> {
103103
if self.config.systemd_listen {
104104
match listenfd::ListenFd::from_env().take_tcp_listener(0) {
105-
Ok(Some(res)) => Ok(Some(res)),
105+
Ok(Some(res)) => {
106+
if let Err(err) = res.set_nonblocking(true) {
107+
error!(
108+
"Fatal: error switching systemd socket to \
109+
nonblocking: {err}"
110+
);
111+
return Err(Failed);
112+
}
113+
Ok(Some(res))
114+
}
106115
Ok(None) => {
107116
error!(
108117
"Fatal: systemd_listen enabled \

0 commit comments

Comments
 (0)