Skip to content

Pluggable discovery (WIP) #109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 12 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
discovery: added timeout on LIST command
  • Loading branch information
cmaglie committed Jan 7, 2019
commit e50f3913ec2824e425f1dd9dadc59daa61292b2c
17 changes: 17 additions & 0 deletions arduino/discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import (
"fmt"
"io"
"os/exec"
"time"

"github.com/arduino/arduino-cli/arduino/cores/packagemanager"

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

Expand Down Expand Up @@ -87,9 +90,23 @@ func (d *Discovery) List() ([]*BoardPort, error) {
return nil, fmt.Errorf("sending LIST command to discovery: %s", err)
}
var event eventJSON
done := make(chan bool)
timeout := false
go func() {
select {
case <-done:
case <-time.After(5 * time.Second):
timeout = true
d.Close()
}
}()
if err := d.outJSON.Decode(&event); err != nil {
if timeout {
return nil, fmt.Errorf("decoding LIST command: timeout")
}
return nil, fmt.Errorf("decoding LIST command: %s", err)
}
done <- true
return event.Ports, nil
}

Expand Down