Skip to content

Commit 5d762a6

Browse files
server: Fix the peek_stream function
Since we set the stream as non-blocking, the call to fill-buf will return an Err variant if no data is available. We want to catch that case and simply return false. Else, if the function returns an Error, the set-blocking function wouldn't be called.
1 parent 545ab88 commit 5d762a6

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

crates/server/src/lib.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,13 @@ fn peek_stream(
100100
duration: Duration,
101101
) -> io::Result<bool> {
102102
stream.get_mut().set_non_blocking(duration)?;
103-
let result = !stream.fill_buf()?.is_empty();
103+
let result = match stream.fill_buf() {
104+
Ok(b) => !b.is_empty(),
105+
Err(err) => match err.kind() {
106+
io::ErrorKind::WouldBlock => false,
107+
_ => return Err(err),
108+
},
109+
};
104110
stream.get_mut().set_blocking()?;
105111
Ok(result)
106112
}
@@ -123,7 +129,11 @@ fn handle_connection(
123129
let offset = keep_alive_timeout - start.elapsed();
124130

125131
match peek_stream(req.stream_mut(), offset) {
126-
Ok(false) | Err(_) => break,
132+
Ok(false) => break,
133+
Err(err) => {
134+
log_error!("Error on peek_stream: {err}");
135+
break;
136+
}
127137
_ => {}
128138
}
129139

0 commit comments

Comments
 (0)