Skip to content

Commit a057733

Browse files
author
Miloš Vučenović
committed
Fix uds listener hanging on accept
UDS listener was hanging because the accept method would return `Poll::Pending` without registering the task to be awoken in the case when underlying unix listener returns a WouldBlock that gets converted to None. This is a hacky fix for this case. Should fix async-rs#248
1 parent 98c79f4 commit a057733

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/os/unix/net/listener.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,25 @@ impl UnixListener {
9393
/// ```
9494
pub async fn accept(&self) -> io::Result<(UnixStream, SocketAddr)> {
9595
future::poll_fn(|cx| {
96-
let res =
97-
futures_core::ready!(self.watcher.poll_read_with(cx, |inner| inner.accept_std()));
96+
let res = futures_core::ready!(self.watcher.poll_read_with(cx, |inner| {
97+
match inner.accept_std() {
98+
// Converting to `would block` so that the watcher will
99+
// add the waker of this task to a list of readers.
100+
Ok(None) => Err(std::io::ErrorKind::WouldBlock.into()),
101+
res => res,
102+
}
103+
}));
98104

99105
match res? {
100-
None => Poll::Pending,
101106
Some((io, addr)) => {
102107
let mio_stream = mio_uds::UnixStream::from_stream(io)?;
103108
let stream = UnixStream {
104109
watcher: Watcher::new(mio_stream),
105110
};
106111
Poll::Ready(Ok((stream, addr)))
107112
}
113+
// This should never happen since None is converted to WouldBlock
114+
None => unreachable!(),
108115
}
109116
})
110117
.await

0 commit comments

Comments
 (0)