Skip to content

Commit

Permalink
fix: move incoming conn handling off thread to not block
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuef committed Feb 21, 2023
1 parent cb55c71 commit d1624cb
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,23 @@ pub(super) fn listen_for_incoming_connections(
) {
let _handle = tokio::spawn(async move {
while let Some(quinn_conn) = quinn_endpoint.accept().await {
match quinn_conn.await {
Ok(connection) => {
let connection = Connection::new(connection);
let conn_id = connection.0.id();
trace!("Incoming new connection conn_id={conn_id}");
if connection_tx.send(connection).await.is_err() {
warn!("Dropping incoming connection conn_id={conn_id}, because receiver was dropped");
let conn_sender = connection_tx.clone();
// move incoming conn waiting off thread so as not to block us
let _handle = tokio::spawn(async move {
match quinn_conn.await {
Ok(connection) => {
let connection = Connection::new(connection);
let conn_id = connection.0.id();
trace!("Incoming new connection conn_id={conn_id}");
if conn_sender.send(connection).await.is_err() {
warn!("Dropping incoming connection conn_id={conn_id}, because receiver was dropped");
}
}
Err(err) => {
warn!("An incoming connection failed because of: {:?}", err);
}
}
Err(err) => {
warn!("An incoming connection failed because of: {:?}", err);
}
}
});
}

trace!(
Expand Down

0 comments on commit d1624cb

Please sign in to comment.