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
Do not cache ports in the DiscoveryClient
there is already a cache in the DiscoveryManager there is no need to
duplicate it.
  • Loading branch information
cmaglie committed Aug 10, 2022
commit aeec293d25d8f5830f551db67af41b856bbc5ff7
23 changes: 0 additions & 23 deletions arduino/discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ type PluggableDiscovery struct {
incomingMessagesError error
state int
eventChan chan<- *Event
cachedPorts map[string]*Port
}

type discoveryMessage struct {
Expand Down Expand Up @@ -132,7 +131,6 @@ func New(id string, args ...string) *PluggableDiscovery {
id: id,
processArgs: args,
state: Dead,
cachedPorts: map[string]*Port{},
}
}

Expand Down Expand Up @@ -177,7 +175,6 @@ func (disc *PluggableDiscovery) jsonDecodeLoop(in io.Reader, outChan chan<- *dis
return
}
disc.statusMutex.Lock()
disc.cachedPorts[msg.Port.Address+"|"+msg.Port.Protocol] = msg.Port
if disc.eventChan != nil {
disc.eventChan <- &Event{"add", msg.Port, disc.GetID()}
}
Expand All @@ -188,7 +185,6 @@ func (disc *PluggableDiscovery) jsonDecodeLoop(in io.Reader, outChan chan<- *dis
return
}
disc.statusMutex.Lock()
delete(disc.cachedPorts, msg.Port.Address+"|"+msg.Port.Protocol)
if disc.eventChan != nil {
disc.eventChan <- &Event{"remove", msg.Port, disc.GetID()}
}
Expand Down Expand Up @@ -371,12 +367,6 @@ func (disc *PluggableDiscovery) Stop() error {

func (disc *PluggableDiscovery) stopSync() {
if disc.eventChan != nil {
// When stopping sync send a batch of "remove" events for
// all the active ports.
for _, port := range disc.cachedPorts {
disc.eventChan <- &Event{"remove", port, disc.GetID()}
}
disc.cachedPorts = map[string]*Port{}
disc.eventChan <- &Event{"stop", nil, disc.GetID()}
close(disc.eventChan)
disc.eventChan = nil
Expand Down Expand Up @@ -440,16 +430,3 @@ func (disc *PluggableDiscovery) StartSync(size int) (<-chan *Event, error) {
disc.eventChan = c
return c, nil
}

// ListCachedPorts returns a list of the available ports. The list is a cache of all the
// add/remove events happened from the StartSync call and it will not consume any
// resource from the underliying discovery.
func (disc *PluggableDiscovery) ListCachedPorts() []*Port {
disc.statusMutex.Lock()
defer disc.statusMutex.Unlock()
res := []*Port{}
for _, port := range disc.cachedPorts {
res = append(res, port)
}
return res
}
17 changes: 16 additions & 1 deletion arduino/discovery/discoverymanager/discoverymanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,22 @@ func (dm *DiscoveryManager) feedEvent(ev *discovery.Event) {
}

if ev.Type == "stop" {
// Remove all the cached events for the terminating discovery
// Send remove events for all the cached ports of the terminating discovery
cache := dm.watchersCache[ev.DiscoveryID]
for _, addEv := range cache {
removeEv := &discovery.Event{
Type: "remove",
Port: &discovery.Port{
Address: addEv.Port.Address,
AddressLabel: addEv.Port.AddressLabel,
Protocol: addEv.Port.Protocol,
ProtocolLabel: addEv.Port.ProtocolLabel},
DiscoveryID: addEv.DiscoveryID,
}
sendToAllWatchers(removeEv)
}

// Remove the cache for the terminating discovery
delete(dm.watchersCache, ev.DiscoveryID)
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