Skip to content

Commit 236742c

Browse files
committed
Correctly clean-up pluggable-discoveries on gRPC instance close
1 parent baa2ab0 commit 236742c

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

commands/internal/instances/instances.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,12 @@ func IsValid(inst *rpc.Instance) bool {
172172
// Delete removes an instance.
173173
func Delete(inst *rpc.Instance) bool {
174174
instancesMux.Lock()
175-
defer instancesMux.Unlock()
176-
if _, ok := instances[inst.GetId()]; !ok {
175+
instance, ok := instances[inst.GetId()]
176+
delete(instances, inst.GetId())
177+
instancesMux.Unlock()
178+
if !ok {
177179
return false
178180
}
179-
delete(instances, inst.GetId())
181+
instance.pm.Destroy()
180182
return true
181183
}

internal/arduino/cores/packagemanager/package_manager.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,11 @@ func (pm *PackageManager) NewExplorer() (explorer *Explorer, release func()) {
197197
}, pm.packagesLock.RUnlock
198198
}
199199

200+
// Destroy releases all resources held by the PackageManager.
201+
func (pm *PackageManager) Destroy() {
202+
pm.discoveryManager.Clear()
203+
}
204+
200205
// GetProfile returns the active profile for this package manager, or nil if no profile is selected.
201206
func (pme *Explorer) GetProfile() *sketch.Profile {
202207
return pme.profile

0 commit comments

Comments
 (0)