Skip to content

Commit

Permalink
unbuffered-async-client: attempt to fix flickeryness
Browse files Browse the repository at this point in the history
In this case the server's response was split over two packets.
Most of the time these arrived together and the test passed.

In the case where the server's second packet was slightly
delayed, we'd see the first one (but not be able to process it)
and then send a close_notify, and clear the `open_connection` flag.

That meant we dropped out of the loop with non-zero `incoming_used`;
this failed an assertion.

Instead: track received/sent close_notify separately, and try to read
any remaining incoming data.
  • Loading branch information
ctz committed Jun 21, 2024
1 parent 242c570 commit 59da9b5
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions examples/src/bin/unbuffered-async-client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@ async fn converse(
let mut incoming_used = 0;
let mut outgoing_used = 0;

let mut open_connection = true;
let mut we_closed = false;
let mut peer_closed = false;
let mut sent_request = false;
let mut received_response = false;

let mut iter_count = 0;
while open_connection {
while !(peer_closed || (we_closed && incoming_used == 0)) {
let UnbufferedStatus { mut discard, state } =
conn.process_tls_records(&mut incoming_tls[..incoming_used]);

Expand Down Expand Up @@ -134,7 +135,7 @@ async fn converse(
// `TransmitTlsData` state. the server should have already written a
// response which we can read out from the socket
recv_tls(&mut sock, incoming_tls, &mut incoming_used).await?;
} else {
} else if !we_closed {
try_or_resize_and_retry(
|out_buffer| may_encrypt.queue_close_notify(out_buffer),
|e| {
Expand All @@ -148,12 +149,14 @@ async fn converse(
&mut outgoing_used,
)?;
send_tls(&mut sock, outgoing_tls, &mut outgoing_used).await?;
open_connection = false;
we_closed = true;
} else {
recv_tls(&mut sock, incoming_tls, &mut incoming_used).await?;
}
}

ConnectionState::Closed => {
open_connection = false;
peer_closed = true;
}

// other states are not expected in this example
Expand Down

0 comments on commit 59da9b5

Please sign in to comment.