Skip to content

Commit b4855bc

Browse files
committed
pluggable-discovery: better closing procedure
It now correctly closes zombie processes.
1 parent 952de16 commit b4855bc

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

arduino/discovery/discovery.go

+9-11
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,15 @@ func (d *Discovery) List() ([]*BoardPort, error) {
114114

115115
// Close stops the Discovery and free the resources
116116
func (d *Discovery) Close() error {
117-
// TODO: Send QUIT for safe close or terminate process after a small timeout
118-
if err := d.in.Close(); err != nil {
119-
return fmt.Errorf("closing stdin pipe: %s", err)
120-
}
121-
if err := d.out.Close(); err != nil {
122-
return fmt.Errorf("closing stdout pipe: %s", err)
123-
}
124-
if d.cmd != nil {
125-
d.cmd.Process.Kill()
126-
}
127-
return nil
117+
_, _ = d.in.Write([]byte("QUIT\n"))
118+
_ = d.in.Close()
119+
_ = d.out.Close()
120+
timer := time.AfterFunc(time.Second, func() {
121+
_ = d.cmd.Process.Kill()
122+
})
123+
err := d.cmd.Wait()
124+
_ = timer.Stop()
125+
return err
128126
}
129127

130128
// ExtractDiscoveriesFromPlatforms returns all Discovery from all the installed platforms.

0 commit comments

Comments
 (0)