fix race condition caused by relayFinder.ctxCancel
@@ -62,7 +62,9 @@ type relayFinder struct {
conf *config
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()
