From 15df34bc9dfd1d46f379d5c97275aa9035934e42 Mon Sep 17 00:00:00 2001 From: leibeiyi Date: Mon, 3 Jun 2024 15:04:19 +0800 Subject: [PATCH] fix: High CPU Usage (100%) in Specific Scenarios (#781) --- src/codec/framed_write.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/codec/framed_write.rs b/src/codec/framed_write.rs index c88af02da..0d5f17790 100644 --- a/src/codec/framed_write.rs +++ b/src/codec/framed_write.rs @@ -141,11 +141,18 @@ where } _ => { tracing::trace!(queued_data_frame = false); - ready!(poll_write_buf( + let n = ready!(poll_write_buf( Pin::new(&mut self.inner), cx, &mut self.encoder.buf - ))? + ))?; + if n == 0 { + return Poll::Ready(Err(io::Error::new( + io::ErrorKind::WriteZero, + "failed to write frame to socket", + ))); + } + n } }; }