Skip to content

Commit

Permalink
fix(http2): don't send keep-alive ping when idle (hyperium#3381)
Browse files Browse the repository at this point in the history
Signed-off-by: husharp <jinhao.hu@pingcap.com>
  • Loading branch information
HuSharp authored and 0xE282B0 committed Jan 12, 2024
1 parent e22f577 commit c95977f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/proto/h2/ping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ impl Ponger {

if let Some(ref mut ka) = self.keep_alive {
ka.maybe_schedule(is_idle, &locked);
ka.maybe_ping(cx, &mut locked);
ka.maybe_ping(cx, is_idle, &mut locked);
}

if !locked.is_ping_sent() {
Expand All @@ -284,7 +284,7 @@ impl Ponger {
if let Some(ref mut ka) = self.keep_alive {
locked.update_last_read_at();
ka.maybe_schedule(is_idle, &locked);
ka.maybe_ping(cx, &mut locked);
ka.maybe_ping(cx, is_idle, &mut locked);
}

if let Some(ref mut bdp) = self.bdp {
Expand Down Expand Up @@ -448,7 +448,7 @@ impl KeepAlive {
self.timer.reset(&mut self.sleep, interval);
}

fn maybe_ping(&mut self, cx: &mut task::Context<'_>, shared: &mut Shared) {
fn maybe_ping(&mut self, cx: &mut task::Context<'_>, is_idle: bool, shared: &mut Shared) {
match self.state {
KeepAliveState::Scheduled(at) => {
if Pin::new(&mut self.sleep).poll(cx).is_pending() {
Expand All @@ -460,6 +460,10 @@ impl KeepAlive {
cx.waker().wake_by_ref(); // schedule us again
return;
}
if !self.while_idle && is_idle {
trace!("keep-alive no need to ping when idle and while_idle=false");
return;
}
trace!("keep-alive interval ({:?}) reached", self.interval);
shared.send_ping();
self.state = KeepAliveState::PingSent;
Expand Down

0 comments on commit c95977f

Please sign in to comment.