Skip to content

Commit

Permalink
fix: return a WriteZero error if frames cannot be written (#783)
Browse files Browse the repository at this point in the history
Some operating systems will allow you continually call `write()` on a closed socket, and will return `Ok(0)` instead of an error. This patch checks for a zero write, and instead of looping forever trying to write, returns a proper error.

Closes #781

Co-authored-by: leibeiyi <[email protected]>
  • Loading branch information
niceskylei and leibeiyi authored Jun 3, 2024
1 parent 357127e commit e6e3e9c
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/codec/framed_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ where

loop {
while !self.encoder.is_empty() {
match self.encoder.next {
let n = match self.encoder.next {
Some(Next::Data(ref mut frame)) => {
tracing::trace!(queued_data_frame = true);
let mut buf = (&mut self.encoder.buf).chain(frame.payload_mut());
Expand All @@ -148,6 +148,12 @@ where
))?
}
};
if n == 0 {
return Poll::Ready(Err(io::Error::new(
io::ErrorKind::WriteZero,
"failed to write frame to socket",
)));
}
}

match self.encoder.unset_frame() {
Expand Down

0 comments on commit e6e3e9c

Please sign in to comment.