From 72df25af76e4c5019c80893d3b5664e15ce53d96 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 27 Jul 2018 10:54:34 -0700 Subject: [PATCH] always reset ping streams when done Currently, we leak a stream. We could use FullClose but, IMO, it's not worth it. We might as well just reset and walk away. --- p2p/protocol/ping/ping.go | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/p2p/protocol/ping/ping.go b/p2p/protocol/ping/ping.go index 54464f30..ae0c47f7 100644 --- a/p2p/protocol/ping/ping.go +++ b/p2p/protocol/ping/ping.go @@ -44,19 +44,14 @@ func (p *PingService) PingHandler(s inet.Stream) { select { case <-timer.C: log.Debug("ping timeout") - s.Reset() case err, ok := <-errCh: if ok { log.Debug(err) - if err == io.EOF { - s.Close() - } else { - s.Reset() - } } else { log.Error("ping loop failed without error") } } + s.Reset() }() for { @@ -85,7 +80,7 @@ func (ps *PingService) Ping(ctx context.Context, p peer.ID) (<-chan time.Duratio out := make(chan time.Duration) go func() { defer close(out) - defer s.Close() + defer s.Reset() for { select { case <-ctx.Done(): @@ -93,7 +88,6 @@ func (ps *PingService) Ping(ctx context.Context, p peer.ID) (<-chan time.Duratio default: t, err := ping(s) if err != nil { - s.Reset() log.Debugf("ping error: %s", err) return }