exits send_datagram_task if the connection is closed (#33836)
Waiting on receiver.recv() can unnecessarily block while the connection is already closed. The commit exits send_datagram_task if the connection is closed.
This commit is contained in:
parent
bbb58c20d2
commit
03fbe083b8
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue