Browse Source

ping: use context.Afterfunc to avoid a lingering goroutine (#2723)

pull/2725/head
Jorropo 8 months ago
committed by GitHub
parent
commit
16d3bffa92
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 5
      p2p/protocol/ping/ping.go

5
p2p/protocol/ping/ping.go

@ -158,11 +158,10 @@ func Ping(ctx context.Context, h host.Host, p peer.ID) <-chan Result {
}
}
}()
go func() {
context.AfterFunc(ctx, func() {
// forces the ping to abort.
<-ctx.Done()
s.Reset()
}()
})
return out
}

Loading…
Cancel
Save