Merge pull request #380 from libp2p/fix/reset-ping-stream

always reset ping streams when done
This commit is contained in:
Steven Allen 2018-08-21 05:22:22 +00:00 committed by GitHub
commit 7d6f9521c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 8 deletions

View File

@ -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
}