Skip to content

Commit 8905926

Browse files
committed
discovery: added timeout on LIST command
1 parent a91c8a5 commit 8905926

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

arduino/discovery/discovery.go

+17
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ import (
2222
"fmt"
2323
"io"
2424
"os/exec"
25+
"time"
26+
27+
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
2528

2629
properties "github.com/arduino/go-properties-orderedmap"
2730

@@ -87,9 +90,23 @@ func (d *Discovery) List() ([]*BoardPort, error) {
8790
return nil, fmt.Errorf("sending LIST command to discovery: %s", err)
8891
}
8992
var event eventJSON
93+
done := make(chan bool)
94+
timeout := false
95+
go func() {
96+
select {
97+
case <-done:
98+
case <-time.After(5 * time.Second):
99+
timeout = true
100+
d.Close()
101+
}
102+
}()
90103
if err := d.outJSON.Decode(&event); err != nil {
104+
if timeout {
105+
return nil, fmt.Errorf("decoding LIST command: timeout")
106+
}
91107
return nil, fmt.Errorf("decoding LIST command: %s", err)
92108
}
109+
done <- true
93110
return event.Ports, nil
94111
}
95112

0 commit comments

Comments
 (0)