From 7037b52474a9d38293c04bb5580a37dd112bdbf9 Mon Sep 17 00:00:00 2001 From: Alexis Sellier Date: Thu, 11 May 2023 14:52:55 +0200 Subject: [PATCH] node: Read with timeout from worker channel This change ensures that if we're waiting on a Git request packetline that never arrives, we time out. --- radicle-node/src/worker/channels.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/radicle-node/src/worker/channels.rs b/radicle-node/src/worker/channels.rs index e1ee40d7..f623da7d 100644 --- a/radicle-node/src/worker/channels.rs +++ b/radicle-node/src/worker/channels.rs @@ -131,7 +131,7 @@ impl Read for ChannelReader> { return Ok(read); } - match self.receiver.recv() { + match self.receiver.recv_timeout(self.timeout) { Ok(ChannelEvent::Data(data)) => { self.buffer = io::Cursor::new(data); self.buffer.read(buf) @@ -139,7 +139,11 @@ impl Read for ChannelReader> { Ok(ChannelEvent::Eof) => Err(io::ErrorKind::UnexpectedEof.into()), Ok(ChannelEvent::Close) => Err(io::ErrorKind::ConnectionReset.into()), - Err(_) => Err(io::Error::new( + Err(chan::RecvTimeoutError::Timeout) => Err(io::Error::new( + io::ErrorKind::TimedOut, + "error reading from stream: channel timed out", + )), + Err(chan::RecvTimeoutError::Disconnected) => Err(io::Error::new( io::ErrorKind::BrokenPipe, "error reading from stream: channel is disconnected", )),