From 715de0b7f6bc5c089656a37a4b299dc1138bc394 Mon Sep 17 00:00:00 2001 From: frank Date: Mon, 15 Apr 2024 21:20:18 +0800 Subject: [PATCH] fix_: logout deadlock --- go.mod | 2 +- go.sum | 4 ++-- .../waku/v2/service/common_discovery_service.go | 2 -- .../go-waku/waku/v2/service/common_service.go | 15 ++++++++------- vendor/modules.txt | 2 +- 5 files changed, 12 insertions(+), 13 deletions(-) diff --git a/go.mod b/go.mod index 1af517193aa..b3e11c03f79 100644 --- a/go.mod +++ b/go.mod @@ -90,7 +90,7 @@ require ( github.com/schollz/peerdiscovery v1.7.0 github.com/siphiuel/lc-proxy-wrapper v0.0.0-20230516150924-246507cee8c7 github.com/urfave/cli/v2 v2.24.4 - github.com/waku-org/go-waku v0.8.1-0.20240322182925-dd81e1d46971 + github.com/waku-org/go-waku v0.8.1-0.20240415131212-6d889ca3e2fe github.com/wk8/go-ordered-map/v2 v2.1.7 github.com/yeqown/go-qrcode/v2 v2.2.1 github.com/yeqown/go-qrcode/writer/standard v1.2.1 diff --git a/go.sum b/go.sum index 0fcdcefde04..9b774534ac3 100644 --- a/go.sum +++ b/go.sum @@ -2101,8 +2101,8 @@ github.com/waku-org/go-discover v0.0.0-20240129014929-85f2c00b96a3 h1:Kk0KYXZE/u github.com/waku-org/go-discover v0.0.0-20240129014929-85f2c00b96a3/go.mod h1:eBHgM6T4EG0RZzxpxKy+rGz/6Dw2Nd8DWxS0lm9ESDw= github.com/waku-org/go-libp2p-rendezvous v0.0.0-20230628220917-7b4e5ae4c0e7 h1:0e1h+p84yBp0IN7AqgbZlV7lgFBjm214lgSOE7CeJmE= github.com/waku-org/go-libp2p-rendezvous v0.0.0-20230628220917-7b4e5ae4c0e7/go.mod h1:pFvOZ9YTFsW0o5zJW7a0B5tr1owAijRWJctXJ2toL04= -github.com/waku-org/go-waku v0.8.1-0.20240322182925-dd81e1d46971 h1:HSR8JmscSmCtpIAzFO5sNZRyYZbO8nw7rGM3QcC9bak= -github.com/waku-org/go-waku v0.8.1-0.20240322182925-dd81e1d46971/go.mod h1:RjTvkTrIwpoT1cM9HeQqwa2Q7t7WOkb3hpuB/zuZ6SM= +github.com/waku-org/go-waku v0.8.1-0.20240415131212-6d889ca3e2fe h1:rJF7qKODzvWx03iaLbYyjvA62crnCaDqIN661aqCQ8c= +github.com/waku-org/go-waku v0.8.1-0.20240415131212-6d889ca3e2fe/go.mod h1:RjTvkTrIwpoT1cM9HeQqwa2Q7t7WOkb3hpuB/zuZ6SM= github.com/waku-org/go-zerokit-rln v0.1.14-0.20240102145250-fa738c0bdf59 h1:jisj+OCI6QydLtFq3Pyhu49wl9ytPN7oAHjMfepHDrA= github.com/waku-org/go-zerokit-rln v0.1.14-0.20240102145250-fa738c0bdf59/go.mod h1:1PdBdPzyTaKt3VnpAHk3zj+r9dXPFOr3IHZP9nFle6E= github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230916172309-ee0ee61dde2b h1:KgZVhsLkxsj5gb/FfndSCQu6VYwALrCOgYI3poR95yE= diff --git a/vendor/github.com/waku-org/go-waku/waku/v2/service/common_discovery_service.go b/vendor/github.com/waku-org/go-waku/waku/v2/service/common_discovery_service.go index c22f18f111d..651c349bf09 100644 --- a/vendor/github.com/waku-org/go-waku/waku/v2/service/common_discovery_service.go +++ b/vendor/github.com/waku-org/go-waku/waku/v2/service/common_discovery_service.go @@ -49,8 +49,6 @@ func (sp *CommonDiscoveryService) GetListeningChan() <-chan PeerData { return sp.channel } func (sp *CommonDiscoveryService) PushToChan(data PeerData) bool { - sp.RLock() - defer sp.RUnlock() if err := sp.ErrOnNotRunning(); err != nil { return false } diff --git a/vendor/github.com/waku-org/go-waku/waku/v2/service/common_service.go b/vendor/github.com/waku-org/go-waku/waku/v2/service/common_service.go index 9bf3ea12ba2..026651e425b 100644 --- a/vendor/github.com/waku-org/go-waku/waku/v2/service/common_service.go +++ b/vendor/github.com/waku-org/go-waku/waku/v2/service/common_service.go @@ -4,6 +4,7 @@ import ( "context" "errors" "sync" + "sync/atomic" ) // this is common layout for all the services that require mutex protection and a guarantee that all running goroutines will be finished before stop finishes execution. This guarantee comes from waitGroup all one has to use CommonService.WaitGroup() in the goroutines that should finish by the end of stop function. @@ -12,7 +13,7 @@ type CommonService struct { cancel context.CancelFunc ctx context.Context wg sync.WaitGroup - started bool + started atomic.Bool } func NewCommonService() *CommonService { @@ -28,13 +29,13 @@ func NewCommonService() *CommonService { func (sp *CommonService) Start(ctx context.Context, fn func() error) error { sp.Lock() defer sp.Unlock() - if sp.started { + if sp.started.Load() { return ErrAlreadyStarted } - sp.started = true + sp.started.Store(true) sp.ctx, sp.cancel = context.WithCancel(ctx) if err := fn(); err != nil { - sp.started = false + sp.started.Store(false) sp.cancel() return err } @@ -48,18 +49,18 @@ var ErrNotStarted = errors.New("not started") func (sp *CommonService) Stop(fn func()) { sp.Lock() defer sp.Unlock() - if !sp.started { + if !sp.started.Load() { return } sp.cancel() fn() sp.wg.Wait() - sp.started = false + sp.started.Store(false) } // This is not a mutex protected function, it is up to the caller to use it in a mutex protected context func (sp *CommonService) ErrOnNotRunning() error { - if !sp.started { + if !sp.started.Load() { return ErrNotStarted } return nil diff --git a/vendor/modules.txt b/vendor/modules.txt index d28af764ff7..69bb273f2f2 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1020,7 +1020,7 @@ github.com/waku-org/go-discover/discover/v5wire github.com/waku-org/go-libp2p-rendezvous github.com/waku-org/go-libp2p-rendezvous/db github.com/waku-org/go-libp2p-rendezvous/pb -# github.com/waku-org/go-waku v0.8.1-0.20240322182925-dd81e1d46971 +# github.com/waku-org/go-waku v0.8.1-0.20240415131212-6d889ca3e2fe ## explicit; go 1.19 github.com/waku-org/go-waku/logging github.com/waku-org/go-waku/waku/persistence