Skip to content

Commit

Permalink
Ensure the ping interval waker is registered
Browse files Browse the repository at this point in the history
When an interval is ready it does not need to register its internal
waker, leading to the future not being polled anymore if no data is
received from the connection.

The fix is pretty simple, and it should never cause any problem unless
the interval duration is very close to zero, which will probably cause
strange issues anyway.
  • Loading branch information
dodomorandi authored Jan 26, 2024
1 parent d668201 commit a1876c4
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion async-nats/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,10 @@ impl ConnectionHandler {
/// [`Self::receiver`] was closed, so there's nothing
/// more for us to do than to exit the client.
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
if self.handler.ping_interval.poll_tick(cx).is_ready() {
// We need to be sure the waker is registered, therefore we need to poll until we
// get a `Poll::Pending`. With a sane interval delay, this means that the loop
// breaks at the second iteration.
while self.handler.ping_interval.poll_tick(cx).is_ready() {
if let Poll::Ready(exit) = self.ping() {
return Poll::Ready(exit);
}
Expand Down

0 comments on commit a1876c4

Please sign in to comment.