diff --git a/p2p/protocol/ping/ping.go b/p2p/protocol/ping/ping.go index 6ff5c3fb6f..1c78229084 100644 --- a/p2p/protocol/ping/ping.go +++ b/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 }