Skip to content

Commit

Permalink
delay pong
Browse files Browse the repository at this point in the history
  • Loading branch information
sukunrt committed Sep 28, 2023
1 parent be28bd8 commit a0bf064
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions p2p/protocol/ping/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (p *PingService) PingHandler(s network.Stream) {
defer close(errCh)
timer := time.NewTimer(pingTimeout)
defer timer.Stop()

writes := 0
go func() {
select {
case <-timer.C:
Expand All @@ -72,25 +72,23 @@ func (p *PingService) PingHandler(s network.Stream) {
log.Error("ping loop failed without error")
}
}
log.Error("calling ping stream close")
log.Errorln("calling ping stream close", writes)
s.Close()
}()

for {
_, err := io.ReadFull(s, buf)
if err != nil {
log.Error("read failed: ", err)
errCh <- err
return
}
time.Sleep(1 * time.Second)
_, err = s.Write(buf)
if err != nil {
log.Error("write failed: ", err)
errCh <- err
return
}
log.Error("one ping done")
writes++
timer.Reset(pingTimeout)
}
}
Expand Down

0 comments on commit a0bf064

Please sign in to comment.