Skip to content

Commit 1f426b7

Browse files
committed
Discovery: eventChan must be protected by mutex when doing START_SYNC
otherwise the discovery may send some events before the eventChan is setup (and those events will be lost)
1 parent 833a9c8 commit 1f426b7

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Diff for: arduino/discovery/discovery.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,9 @@ func (disc *PluggableDiscovery) List() ([]*Port, error) {
407407
// The event channel must be consumed as quickly as possible since it may block the
408408
// discovery if it becomes full. The channel size is configurable.
409409
func (disc *PluggableDiscovery) StartSync(size int) (<-chan *Event, error) {
410+
disc.statusMutex.Lock()
411+
defer disc.statusMutex.Unlock()
412+
410413
if err := disc.sendCommand("START_SYNC\n"); err != nil {
411414
return nil, err
412415
}
@@ -421,8 +424,6 @@ func (disc *PluggableDiscovery) StartSync(size int) (<-chan *Event, error) {
421424
return nil, errors.Errorf(tr("communication out of sync, expected '%[1]s', received '%[2]s'"), "OK", msg.Message)
422425
}
423426

424-
disc.statusMutex.Lock()
425-
defer disc.statusMutex.Unlock()
426427
disc.state = Syncing
427428
// In case there is already an existing event channel in use we close it before creating a new one.
428429
disc.stopSync()

0 commit comments

Comments
 (0)