Skip to content

Commit

Permalink
Lazily reap finished connections in TokioHandle on spawn_bg
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff-hiner authored and bluejekyll committed Mar 31, 2023
1 parent 6ef52b3 commit 9f196c5
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion crates/resolver/src/name_server/connection_provider.rs
Expand Up @@ -394,7 +394,9 @@ pub mod tokio_runtime {
where
F: Future<Output = Result<(), ProtoError>> + Send + 'static,
{
self.join_set.lock().unwrap().spawn(future);
let mut join_set = self.join_set.lock().unwrap();
join_set.spawn(future);
reap_tasks(&mut join_set);
}
}

Expand Down Expand Up @@ -438,4 +440,9 @@ pub mod tokio_runtime {
Box::pin(tokio::net::UdpSocket::bind(local_addr))
}
}

/// Reap finished tasks from a `JoinSet`, without awaiting or blocking.
fn reap_tasks(join_set: &mut JoinSet<Result<(), ProtoError>>) {
while FutureExt::now_or_never(join_set.join_next()).is_some() {}
}
}

0 comments on commit 9f196c5

Please sign in to comment.