fix(waku2): close discv5 iterator on logout

This commit is contained in:
Richard Ramos 2023-01-31 10:55:44 -04:00 committed by RichΛrd
parent cefa0089dc
commit 17fcd947d2
6 changed files with 34 additions and 7 deletions

View File

@ -1 +1 @@
0.126.0
0.126.1

2
go.mod
View File

@ -77,7 +77,7 @@ require (
github.com/gorilla/sessions v1.2.1
github.com/meirf/gopart v0.0.0-20180520194036-37e9492a85a8
github.com/rmg/iso4217 v1.0.0
github.com/waku-org/go-waku v0.4.1-0.20230130112841-5ff87d8e6550
github.com/waku-org/go-waku v0.4.1-0.20230131145040-6169a44c242f
)
require (

4
go.sum
View File

@ -2067,8 +2067,8 @@ github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae/go.mod h1:DD4vA1
github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0=
github.com/waku-org/go-discover v0.0.0-20221209174356-61c833f34d98 h1:xwY0kW5XZFimdqfZb9cZwT1S3VJP9j3AE6bdNd9boXM=
github.com/waku-org/go-discover v0.0.0-20221209174356-61c833f34d98/go.mod h1:eBHgM6T4EG0RZzxpxKy+rGz/6Dw2Nd8DWxS0lm9ESDw=
github.com/waku-org/go-waku v0.4.1-0.20230130112841-5ff87d8e6550 h1:5Leco+WpKsIEd0QhQzVfHd1YDAxmNuejSaKWOfFrEKI=
github.com/waku-org/go-waku v0.4.1-0.20230130112841-5ff87d8e6550/go.mod h1:sI14mN/sM8inIb2x2b462wydSEFyOyuDKI1cjiVIIpM=
github.com/waku-org/go-waku v0.4.1-0.20230131145040-6169a44c242f h1:nmu8iajX6wTDkoVMOJNfIxXzko7kXcFlSyXYLIMQZkk=
github.com/waku-org/go-waku v0.4.1-0.20230131145040-6169a44c242f/go.mod h1:sI14mN/sM8inIb2x2b462wydSEFyOyuDKI1cjiVIIpM=
github.com/waku-org/go-zerokit-rln v0.1.7-wakuorg h1:2vVIBCtBih2w1K9ll8YnToTDZvbxcgbsClsPlJS/kkg=
github.com/waku-org/go-zerokit-rln v0.1.7-wakuorg/go.mod h1:GlyaVeEWNEBxVJrWC6jFTvb4LNb9d9qnjdS6EiWVUvk=
github.com/wealdtech/go-ens/v3 v3.5.0 h1:Huc9GxBgiGweCOGTYomvsg07K2QggAqZpZ5SuiZdC8o=

View File

@ -256,7 +256,20 @@ func (d *DiscoveryV5) iterate(ctx context.Context) error {
return fmt.Errorf("obtaining iterator: %w", err)
}
defer iterator.Close()
closeCh := make(chan struct{}, 1)
defer close(closeCh)
// Closing iterator when context is cancelled or function is returning
d.wg.Add(1)
go func() {
defer d.wg.Done()
select {
case <-ctx.Done():
iterator.Close()
case <-closeCh:
iterator.Close()
}
}()
for {
if ctx.Err() != nil {

View File

@ -317,7 +317,21 @@ func (wakuPX *WakuPeerExchange) iterate(ctx context.Context) error {
if err != nil {
return fmt.Errorf("obtaining iterator: %w", err)
}
defer iterator.Close()
closeCh := make(chan struct{}, 1)
defer close(closeCh)
// Closing iterator when context is cancelled or function is returning
wakuPX.wg.Add(1)
go func() {
defer wakuPX.wg.Done()
select {
case <-ctx.Done():
iterator.Close()
case <-closeCh:
iterator.Close()
}
}()
for {
if ctx.Err() != nil {

2
vendor/modules.txt vendored
View File

@ -985,7 +985,7 @@ github.com/vacp2p/mvds/transport
github.com/waku-org/go-discover/discover
github.com/waku-org/go-discover/discover/v4wire
github.com/waku-org/go-discover/discover/v5wire
# github.com/waku-org/go-waku v0.4.1-0.20230130112841-5ff87d8e6550
# github.com/waku-org/go-waku v0.4.1-0.20230131145040-6169a44c242f
## explicit; go 1.18
github.com/waku-org/go-waku/logging
github.com/waku-org/go-waku/waku/persistence