Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ping: use context.Afterfunc to avoid a lingering goroutine
Browse files Browse the repository at this point in the history
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
@@ -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
}

0 comments on commit 229de81

Please sign in to comment.