Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5110f0b

Browse filesBrowse files
authored
Fixed a couple of (very rare) race conditions (#2112)
* Fixed concurrent write to variables `err` and `n` * Fix concurrent access to p.cmd.Process The go-routine was spawned before the process was started. This means that p.Kill may read p.cmd.Process before it is written in p.Run.
1 parent 183d5e9 commit 5110f0b
Copy full SHA for 5110f0b

File tree

Expand file treeCollapse file tree

2 files changed

+6
-4
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+6
-4
lines changed

‎arduino/monitor/monitor_test.go

Copy file name to clipboardExpand all lines: arduino/monitor/monitor_test.go
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ func TestDummyMonitor(t *testing.T) {
7474
go func() {
7575
buff := [1024]byte{}
7676
// Receive "TEST" echoed back
77-
n, err = rw.Read(buff[:])
77+
_, err := rw.Read(buff[:])
7878
require.NoError(t, err)
7979
require.Equal(t, 4, n)
8080
require.Equal(t, "TEST", string(buff[:4]))
8181

8282
// Block on read until the port is closed
83-
n, err = rw.Read(buff[:])
83+
_, err = rw.Read(buff[:])
8484
require.ErrorIs(t, err, io.EOF)
8585
atomic.StoreInt32(&completed, 1) // notify completion
8686
}()

‎executils/process.go

Copy file name to clipboardExpand all lines: executils/process.go
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ func (p *Process) SetEnvironment(values []string) {
160160
// RunWithinContext starts the specified command and waits for it to complete. If the given context
161161
// is canceled before the normal process termination, the process is killed.
162162
func (p *Process) RunWithinContext(ctx context.Context) error {
163+
if err := p.Start(); err != nil {
164+
return err
165+
}
163166
completed := make(chan struct{})
164167
defer close(completed)
165168
go func() {
@@ -169,6 +172,5 @@ func (p *Process) RunWithinContext(ctx context.Context) error {
169172
case <-completed:
170173
}
171174
}()
172-
res := p.cmd.Run()
173-
return res
175+
return p.Wait()
174176
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.