Commit f98cd2b4 authored by Cristian Maglie's avatar Cristian Maglie

pluggable-discovery: better closing procedure

It now correctly closes zombie processes.
parent e8e359b9
...@@ -114,17 +114,15 @@ func (d *Discovery) List() ([]*BoardPort, error) { ...@@ -114,17 +114,15 @@ func (d *Discovery) List() ([]*BoardPort, error) {
// Close stops the Discovery and free the resources // Close stops the Discovery and free the resources
func (d *Discovery) Close() error { func (d *Discovery) Close() error {
// TODO: Send QUIT for safe close or terminate process after a small timeout _, _ = d.in.Write([]byte("QUIT\n"))
if err := d.in.Close(); err != nil { _ = d.in.Close()
return fmt.Errorf("closing stdin pipe: %s", err) _ = d.out.Close()
} timer := time.AfterFunc(time.Second, func() {
if err := d.out.Close(); err != nil { _ = d.cmd.Process.Kill()
return fmt.Errorf("closing stdout pipe: %s", err) })
} err := d.cmd.Wait()
if d.cmd != nil { _ = timer.Stop()
d.cmd.Process.Kill() return err
}
return nil
} }
// ExtractDiscoveriesFromPlatforms returns all Discovery from all the installed platforms. // ExtractDiscoveriesFromPlatforms returns all Discovery from all the installed platforms.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment