Skip to content

Fix gRPC BoardList* methods concurrency issues #1804

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

Merged
merged 15 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Correctly handle discovery cleanup
  • Loading branch information
cmaglie committed Aug 10, 2022
commit 599fd0c17edb005812f8474a210dad1fc2e1aa78
24 changes: 11 additions & 13 deletions arduino/discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,7 @@ func (disc *PluggableDiscovery) killProcess() error {
}
disc.statusMutex.Lock()
defer disc.statusMutex.Unlock()
if disc.eventChan != nil {
close(disc.eventChan)
disc.eventChan = nil
}
disc.stopSync()
disc.state = Dead
logrus.Infof("killed discovery %s process", disc.id)
return nil
Expand Down Expand Up @@ -367,13 +364,18 @@ func (disc *PluggableDiscovery) Stop() error {
}
disc.statusMutex.Lock()
defer disc.statusMutex.Unlock()
disc.cachedPorts = map[string]*Port{}
disc.stopSync()
disc.state = Idling
return nil
}

func (disc *PluggableDiscovery) stopSync() {
if disc.eventChan != nil {
disc.eventChan <- &Event{"stop", nil, disc.GetID()}
close(disc.eventChan)
disc.eventChan = nil
disc.cachedPorts = map[string]*Port{}
}
disc.state = Idling
return nil
}

// Quit terminates the discovery. No more commands can be accepted by the discovery.
Expand Down Expand Up @@ -427,12 +429,8 @@ func (disc *PluggableDiscovery) StartSync(size int) (<-chan *Event, error) {
disc.statusMutex.Lock()
defer disc.statusMutex.Unlock()
disc.state = Syncing
disc.cachedPorts = map[string]*Port{}
if disc.eventChan != nil {
// In case there is already an existing event channel in use we close it
// before creating a new one.
close(disc.eventChan)
}
// In case there is already an existing event channel in use we close it before creating a new one.
disc.stopSync()
c := make(chan *Event, size)
disc.eventChan = c
return c, nil
Expand Down
14 changes: 10 additions & 4 deletions arduino/discovery/discoverymanager/discoverymanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,15 @@ func New() *DiscoveryManager {
// Clear resets the DiscoveryManager to its initial state
func (dm *DiscoveryManager) Clear() {
dm.discoveriesMutex.Lock()
for _, d := range dm.discoveries {
d.Quit()
logrus.Infof("Closed and removed discovery %s", d.GetID())
defer dm.discoveriesMutex.Unlock()

if dm.discoveriesRunning {
for _, d := range dm.discoveries {
d.Quit()
logrus.Infof("Closed and removed discovery %s", d.GetID())
}
}
dm.discoveries = map[string]*discovery.PluggableDiscovery{}
dm.discoveriesMutex.Unlock()
}

// IDs returns the list of discoveries' ids in this DiscoveryManager
Expand Down Expand Up @@ -209,6 +212,9 @@ func (dm *DiscoveryManager) cacheEvent(ev *discovery.Event) {
cache[eventID] = ev
case "remove":
delete(cache, eventID)
case "quit":
// Remove all the events for this discovery
delete(dm.watchersCache, ev.DiscoveryID)
default:
logrus.Errorf("Unhandled event from discovery: %s", ev.Type)
return
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy