Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
exits send_datagram_task if the connection is closed (#33836)
Browse files Browse the repository at this point in the history
Waiting on receiver.recv() can unnecessarily block while the connection is already closed.
The commit exits send_datagram_task if the connection is closed.
  • Loading branch information
behzadnouri authored Dec 5, 2023
1 parent bbb58c2 commit 03fbe08
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions turbine/src/quic_endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,10 +435,21 @@ async fn send_datagram_task(
connection: Connection,
mut receiver: AsyncReceiver<Bytes>,
) -> Result<(), Error> {
while let Some(bytes) = receiver.recv().await {
connection.send_datagram(bytes)?;
tokio::pin! {
let connection_closed = connection.closed();
}
loop {
tokio::select! {
biased;
bytes = receiver.recv() => {
match bytes {
None => return Ok(()),
Some(bytes) => connection.send_datagram(bytes)?,
}
}
err = &mut connection_closed => return Err(Error::from(err)),
}
}
Ok(())
}

async fn make_connection_task(
Expand Down

0 comments on commit 03fbe08

Please sign in to comment.