Skip to content

Commit

Permalink
fix(rustls): read buffer if we received a bufffer full error instead …
Browse files Browse the repository at this point in the history
…of processing new packets

Signed-off-by: Florentin Dubois <[email protected]>
  • Loading branch information
FlorentinDUBOIS committed Oct 21, 2023
1 parent 7d3662c commit ea0b8af
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ impl SocketHandler for FrontRustls {
break;
}

let mut is_rustls_backpressuring = false;
match self.session.read_tls(&mut self.stream) {
Ok(0) => {
can_read = false;
Expand All @@ -196,6 +197,12 @@ impl SocketHandler for FrontRustls {
| ErrorKind::BrokenPipe => {
is_closed = true;
}
// According to rustls comment here https://github.com/rustls/rustls/blob/main/rustls/src/conn.rs#L482-L500,
// [`ErrorKind::Other`] error signal that the buffer is full, we need to read it before processing new packets.
ErrorKind::Other => {
warn!("rustls buffer is full, we will consume it, before processing new incoming packets, to mitigate this issue, you could try to increase the buffer size, {:?}", e);
is_rustls_backpressuring = true;
}
_ => {
error!("could not read TLS stream from socket: {:?}", e);
is_error = true;
Expand All @@ -204,10 +211,12 @@ impl SocketHandler for FrontRustls {
},
}

if let Err(e) = self.session.process_new_packets() {
error!("could not process read TLS packets: {:?}", e);
is_error = true;
break;
if !is_rustls_backpressuring {
if let Err(e) = self.session.process_new_packets() {
error!("could not process read TLS packets: {:?}", e);
is_error = true;
break;
}
}

while !self.session.wants_read() {
Expand Down

0 comments on commit ea0b8af

Please sign in to comment.