Skip to content

Commit

Permalink
fix: don't keepalive when the connection is busy
Browse files Browse the repository at this point in the history
* It's a waste of bandwidth.
* It causes us to think the connection is dead because the other side is too
busy sending us _other_ data to respond to the ping.

fixes #15
  • Loading branch information
Stebalien committed Mar 13, 2020
1 parent 888369a commit bddc294
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,14 @@ func (s *Session) recvLoop() error {
return err
}

// Reset the keepalive timer every time we receive data.
// There's no reason to keepalive if we're active. Worse, if the
// peer is busy sending us stuff, the pong might get stuck
// behind a bunch of data.
if s.keepaliveTimer != nil {
s.keepaliveTimer.Reset(s.config.KeepAliveInterval)
}

// Verify the version
if hdr.Version() != protoVersion {
s.logger.Printf("[ERR] yamux: Invalid protocol version: %d", hdr.Version())
Expand Down

0 comments on commit bddc294

Please sign in to comment.