Skip to content

Commit 67759a6

Browse files
committed
sync board list to avoid race conditions
1 parent 15ee5b1 commit 67759a6

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Diff for: arduino/discovery/discovery.go

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"io"
2424
"os/exec"
2525
"strings"
26+
"sync"
2627
"time"
2728

2829
"github.com/arduino/arduino-cli/arduino/cores"
@@ -33,6 +34,7 @@ import (
3334

3435
// Discovery is an instance of a discovery tool
3536
type Discovery struct {
37+
sync.Mutex
3638
ID string
3739
in io.WriteCloser
3840
out io.ReadCloser
@@ -88,6 +90,7 @@ func (d *Discovery) Start() error {
8890

8991
// List retrieve the port list from this discovery
9092
func (d *Discovery) List() ([]*BoardPort, error) {
93+
d.Lock()
9194
if _, err := d.in.Write([]byte("LIST\n")); err != nil {
9295
return nil, fmt.Errorf("sending LIST command to discovery: %s", err)
9396
}
@@ -109,6 +112,7 @@ func (d *Discovery) List() ([]*BoardPort, error) {
109112
return nil, fmt.Errorf("decoding LIST command: %s", err)
110113
}
111114
done <- true
115+
d.Unlock()
112116
return event.Ports, nil
113117
}
114118

0 commit comments

Comments
 (0)