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 3999d9b
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions p2p/protocol/ping/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +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 3999d9b

Please sign in to comment.