Skip to content

Commit 6689e22

Browse files
committed
chore: introduce MAX_FRAME_BUFFER
1 parent cf6456f commit 6689e22

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

yamux/src/connection.rs

+8
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ use std::{fmt, sync::Arc, task::Poll};
3737

3838
pub use stream::{Packet, State, Stream};
3939

40+
/// Max queued frames in `Connection`.
41+
const MAX_FRAME_BUFFER: usize = 2000;
42+
4043
/// How the connection is used.
4144
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
4245
pub enum Mode {
@@ -398,6 +401,11 @@ impl<T: AsyncRead + AsyncWrite + Unpin> Active<T> {
398401
}
399402
}
400403

404+
// Receiver is not reading.
405+
if self.pending_frames.len() == MAX_FRAME_BUFFER {
406+
return Poll::Ready(Err(ConnectionError::Closed));
407+
}
408+
401409
match self.socket.poll_flush_unpin(cx)? {
402410
Poll::Ready(()) => {}
403411
Poll::Pending => {}

0 commit comments

Comments
 (0)