mirror of https://github.com/status-im/go-waku.git
fix: goroutine leak on ping
This commit is contained in:
parent
5744879242
commit
5f3df9343c
|
@ -695,13 +695,26 @@ func (w *WakuNode) startKeepAlive(t time.Duration) {
|
||||||
|
|
||||||
w.ping = ping.NewPingService(w.host)
|
w.ping = ping.NewPingService(w.host)
|
||||||
ticker := time.NewTicker(t)
|
ticker := time.NewTicker(t)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
for _, peer := range w.host.Network().Peers() {
|
for _, p := range w.host.Network().Peers() {
|
||||||
log.Debug("Pinging", peer)
|
log.Debug("Pinging ", p)
|
||||||
w.ping.Ping(w.ctx, peer)
|
go func(peer peer.ID) {
|
||||||
|
ctx, cancel := context.WithTimeout(w.ctx, 3*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
pr := w.ping.Ping(ctx, peer)
|
||||||
|
select {
|
||||||
|
case res := <-pr:
|
||||||
|
if res.Error != nil {
|
||||||
|
log.Error(fmt.Sprintf("Could not ping %s: %s", peer, res.Error.Error()))
|
||||||
|
}
|
||||||
|
case <-ctx.Done():
|
||||||
|
log.Error(fmt.Sprintf("Could not ping %s: %s", peer, ctx.Err()))
|
||||||
|
}
|
||||||
|
}(p)
|
||||||
}
|
}
|
||||||
case <-w.quit:
|
case <-w.quit:
|
||||||
ticker.Stop()
|
ticker.Stop()
|
||||||
|
|
Loading…
Reference in New Issue