Skip to content

Commit

Permalink
Fixed a race condition in discovery manager
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaglie committed Mar 14, 2024
1 parent 6093927 commit 56733ee
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,13 @@ func (dm *DiscoveryManager) Watch() (*PortWatcher, error) {
}
go func() {
dm.watchersMutex.Lock()
defer dm.watchersMutex.Unlock()

// if watcher is still online...
if _, ok := dm.watchers[watcher]; ok {
return
}

// When a watcher is started, send all the current active ports first...
for _, cache := range dm.watchersCache {
for _, ev := range cache {
Expand All @@ -181,7 +188,6 @@ func (dm *DiscoveryManager) Watch() (*PortWatcher, error) {
}
// ...and after that add the watcher to the list of watchers receiving events
dm.watchers[watcher] = true
dm.watchersMutex.Unlock()
}()
return watcher, nil
}
Expand Down

0 comments on commit 56733ee

Please sign in to comment.