Skip to content

Commit

Permalink
ping: use context.Afterfunc to avoid a lingering goroutine
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorropo committed Mar 5, 2024
1 parent 6130b9c commit 229de81
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions p2p/protocol/ping/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 229de81

Please sign in to comment.