From 229de815135f1c123146ff1b3b58c5006c2eda2b Mon Sep 17 00:00:00 2001 From: Jorropo Date: Tue, 5 Mar 2024 06:48:10 +0100 Subject: [PATCH] ping: use context.Afterfunc to avoid a lingering goroutine --- p2p/protocol/ping/ping.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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 }