Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix race condition in relayFinder #1469

Merged
merged 1 commit into from
May 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions p2p/host/autorelay/relay_finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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")
}
Expand All @@ -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()
Expand Down