Skip to content

Commit a411b70

Browse files
committed
When a discovery is quitted ensure that the process gets Wait-ed
Otherwise the resources allocated by the process will be leaked. (pipes, zombie process, etc.)
1 parent c4e19c1 commit a411b70

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

arduino/discovery/discovery.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,15 @@ func (disc *PluggableDiscovery) killProcess() error {
268268
if err := disc.process.Kill(); err != nil {
269269
return err
270270
}
271+
if err := disc.process.Wait(); err != nil {
272+
return err
273+
}
271274
disc.statusMutex.Lock()
272275
defer disc.statusMutex.Unlock()
276+
if disc.eventChan != nil {
277+
close(disc.eventChan)
278+
disc.eventChan = nil
279+
}
273280
disc.state = Dead
274281
logrus.Infof("killed discovery %s process", disc.id)
275282
return nil
@@ -371,13 +378,7 @@ func (disc *PluggableDiscovery) Quit() error {
371378
} else if msg.Message != "OK" || msg.Error {
372379
return errors.Errorf(tr("command failed: %s"), msg.Message)
373380
}
374-
disc.statusMutex.Lock()
375-
defer disc.statusMutex.Unlock()
376-
if disc.eventChan != nil {
377-
close(disc.eventChan)
378-
disc.eventChan = nil
379-
}
380-
disc.state = Dead
381+
disc.killProcess()
381382
return nil
382383
}
383384

arduino/discovery/discoverymanager/discoverymanager.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func (dm *DiscoveryManager) RunAll() []error {
120120
func (dm *DiscoveryManager) StartAll() []error {
121121
return dm.parallelize(func(d *discovery.PluggableDiscovery) error {
122122
state := d.State()
123-
if state != discovery.Idling || state == discovery.Running {
123+
if state != discovery.Idling {
124124
// Already started
125125
return nil
126126
}

0 commit comments

Comments
 (0)