Merge pull request #380 from libp2p/fix/reset-ping-stream
always reset ping streams when done
This commit is contained in:
commit
7d6f9521c2
|
@ -44,19 +44,14 @@ func (p *PingService) PingHandler(s inet.Stream) {
|
||||||
select {
|
select {
|
||||||
case <-timer.C:
|
case <-timer.C:
|
||||||
log.Debug("ping timeout")
|
log.Debug("ping timeout")
|
||||||
s.Reset()
|
|
||||||
case err, ok := <-errCh:
|
case err, ok := <-errCh:
|
||||||
if ok {
|
if ok {
|
||||||
log.Debug(err)
|
log.Debug(err)
|
||||||
if err == io.EOF {
|
|
||||||
s.Close()
|
|
||||||
} else {
|
|
||||||
s.Reset()
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
log.Error("ping loop failed without error")
|
log.Error("ping loop failed without error")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
s.Reset()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
@ -85,7 +80,7 @@ func (ps *PingService) Ping(ctx context.Context, p peer.ID) (<-chan time.Duratio
|
||||||
out := make(chan time.Duration)
|
out := make(chan time.Duration)
|
||||||
go func() {
|
go func() {
|
||||||
defer close(out)
|
defer close(out)
|
||||||
defer s.Close()
|
defer s.Reset()
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
|
@ -93,7 +88,6 @@ func (ps *PingService) Ping(ctx context.Context, p peer.ID) (<-chan time.Duratio
|
||||||
default:
|
default:
|
||||||
t, err := ping(s)
|
t, err := ping(s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.Reset()
|
|
||||||
log.Debugf("ping error: %s", err)
|
log.Debugf("ping error: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue