Skip to content

Commit

Permalink
Fix connection client task wakeups to prevent hangs
Browse files Browse the repository at this point in the history
  • Loading branch information
teor2345 committed Nov 6, 2023
1 parent 9487b7c commit d627322
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions zebra-network/src/peer/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,18 +605,27 @@ impl Service<Request> for Client {
//`ready!` returns `Poll::Pending` when `server_tx` is unready, and
// schedules this task for wakeup.

let mut result = self
.check_heartbeat(cx)
.and_then(|()| self.check_connection(cx));
// Check all the tasks
let heartbeat_result = self.check_heartbeat(cx);
let connection_result = self.check_connection(cx);
let sender_result = self.poll_request(cx);

if result.is_ok() {
result = ready!(self.poll_request(cx));
}
// Requests should only wait if there is no space in the channel.
let is_pending = sender_result.is_pending();

// Combine the results, include the result inside the poll.
let result = heartbeat_result.and(connection_result).and_then(|_| {
let _pending: Poll<()> = sender_result?;
Ok(())
});

// Shut down the client and connection if there is an error.
if let Err(error) = result {
self.shutdown();

Poll::Ready(Err(error))
} else if is_pending {
Poll::Pending
} else {
Poll::Ready(Ok(()))
}
Expand Down

0 comments on commit d627322

Please sign in to comment.