Skip to content

Commit

Permalink
Don't check for PONG timeout before sending first PING (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
nmeum authored Jun 26, 2022
1 parent 96757fe commit 8240917
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ func (c *Client) pingLoop(ctx context.Context, errs chan error, wg *sync.WaitGro

started := time.Now()
past := false
pingSent := false

for {
select {
Expand All @@ -603,7 +604,7 @@ func (c *Client) pingLoop(ctx context.Context, errs chan error, wg *sync.WaitGro
}

c.conn.mu.RLock()
if time.Since(c.conn.lastPong) > c.Config.PingDelay+(60*time.Second) {
if pingSent && time.Since(c.conn.lastPong) > c.Config.PingDelay+(60*time.Second) {
// It's 60 seconds over what out ping delay is, connection
// has probably dropped.
err := ErrTimedOut{
Expand All @@ -625,6 +626,7 @@ func (c *Client) pingLoop(ctx context.Context, errs chan error, wg *sync.WaitGro
c.conn.mu.Unlock()

c.Cmd.Ping(fmt.Sprintf("%d", time.Now().UnixNano()))
pingSent = true
case <-ctx.Done():
wg.Done()
return
Expand Down

0 comments on commit 8240917

Please sign in to comment.