Skip to content

Commit 229fb97

Browse files
committed
Fixed sporadic IO copy error on CI
The StdoutPipe command explicitly mandate to not call proc.Wait before the pipe is fully copied. > StdoutPipe returns a pipe that will be connected to the command's > standard output when the command starts. > > Wait will close the pipe after seeing the command exit, so most callers > don't need to close the pipe themselves. It is thus incorrect to call > Wait before all reads from the pipe have completed. For the same reason, > it is incorrect to call Run when using StdoutPipe.
1 parent e101f0c commit 229fb97

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

internal/integrationtest/arduino-cli.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -389,22 +389,22 @@ func (cli *ArduinoCLI) run(ctx context.Context, stdoutBuff, stderrBuff io.Writer
389389

390390
cli.t.NoError(cliProc.Start())
391391

392+
if stdoutBuff == nil {
393+
stdoutBuff = io.Discard
394+
}
395+
if stderrBuff == nil {
396+
stderrBuff = io.Discard
397+
}
392398
var wg sync.WaitGroup
393399
wg.Add(2)
394400
go func() {
395401
defer wg.Done()
396-
if stdoutBuff == nil {
397-
stdoutBuff = io.Discard
398-
}
399402
if _, err := io.Copy(stdoutBuff, io.TeeReader(stdout, terminalOut)); err != nil {
400403
fmt.Fprintln(terminalOut, color.HiBlackString("<<< stdout copy error:"), err)
401404
}
402405
}()
403406
go func() {
404407
defer wg.Done()
405-
if stderrBuff == nil {
406-
stderrBuff = io.Discard
407-
}
408408
if _, err := io.Copy(stderrBuff, io.TeeReader(stderr, terminalErr)); err != nil {
409409
fmt.Fprintln(terminalErr, color.HiBlackString("<<< stderr copy error:"), err)
410410
}
@@ -416,8 +416,8 @@ func (cli *ArduinoCLI) run(ctx context.Context, stdoutBuff, stderrBuff io.Writer
416416
}
417417
}()
418418
}
419-
cliErr := cliProc.WaitWithinContext(ctx)
420419
wg.Wait()
420+
cliErr := cliProc.WaitWithinContext(ctx)
421421

422422
return cliErr
423423
}

0 commit comments

Comments
 (0)