Merge pull request #1469 from watjurk/fix/autorelay-race
fix race condition in relayFinder
This commit is contained in:
commit
7b47c4e6b0
|
@ -61,8 +61,10 @@ type relayFinder struct {
|
|||
|
||||
conf *config
|
||||
|
||||
refCount sync.WaitGroup
|
||||
ctxCancel context.CancelFunc
|
||||
refCount sync.WaitGroup
|
||||
|
||||
ctxCancel context.CancelFunc
|
||||
ctxCancelMx sync.Mutex
|
||||
|
||||
peerChan <-chan peer.AddrInfo
|
||||
|
||||
|
@ -581,6 +583,8 @@ func (rf *relayFinder) relayAddrs(addrs []ma.Multiaddr) []ma.Multiaddr {
|
|||
}
|
||||
|
||||
func (rf *relayFinder) Start() error {
|
||||
rf.ctxCancelMx.Lock()
|
||||
defer rf.ctxCancelMx.Unlock()
|
||||
if rf.ctxCancel != nil {
|
||||
return errors.New("relayFinder already running")
|
||||
}
|
||||
|
@ -596,6 +600,8 @@ func (rf *relayFinder) Start() error {
|
|||
}
|
||||
|
||||
func (rf *relayFinder) Stop() error {
|
||||
rf.ctxCancelMx.Lock()
|
||||
defer rf.ctxCancelMx.Unlock()
|
||||
log.Debug("stopping relay finder")
|
||||
if rf.ctxCancel != nil {
|
||||
rf.ctxCancel()
|
||||
|
|
Loading…
Reference in New Issue