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.
This commit is contained in:
Alexis Sellier 2023-05-11 14:52:55 +02:00
parent d758c4f203
commit 7037b52474
No known key found for this signature in database
1 changed files with 6 additions and 2 deletions

View File

@ -131,7 +131,7 @@ impl Read for ChannelReader<Vec<u8>> {
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<Vec<u8>> {
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",
)),