Skip to content

Commit

Permalink
fix(connections): when gracefully finishing uni-stream upon sending b…
Browse files Browse the repository at this point in the history
…ytes, do not remove conn from the pool if an error thrown was caused due to being already closed
  • Loading branch information
bochaco committed Jan 27, 2021
1 parent 2e3219a commit 9bba2ee
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/connections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,17 @@ impl Connection {
pub async fn send_uni(&self, msg: Bytes) -> Result<()> {
let mut send_stream = self.handle_error(self.quic_conn.open_uni().await)?;
self.handle_error(send_msg(&mut send_stream, msg).await)?;
self.handle_error(send_stream.finish().await)?;
Ok(())

// We try to make sure the stream is gracefully closed and the bytes get sent,
// but if it was already closed (perhaps by the peer) then we
// don't remove the connection from the pool.
match send_stream.finish().await {
Ok(()) | Err(quinn::WriteError::Stopped(_)) => Ok(()),
Err(err) => {
self.handle_error(Err(err))?;
Ok(())
}
}
}

/// Gracefully close connection immediatelly
Expand Down

0 comments on commit 9bba2ee

Please sign in to comment.