1
0
Fork 0
mirror of https://code.forgejo.org/forgejo/runner.git synced 2025-10-10 19:32:04 +00:00

fix: ptyWriter.AutoStop is used by multiple goroutines

```
WARNING: DATA RACE
Write at 0x00c0008541d8 by goroutine 9324:
  code.forgejo.org/forgejo/runner/v11/act/container.(*HostEnvironment).exec()
      /home/debian/.cache/act/37b13738279f9342/hostexecutor/act/container/host_environment.go:368 +0x12dd
  code.forgejo.org/forgejo/runner/v11/act/runner.(*stepRun).main.func1.(*HostEnvironment).ExecWithCmdLine.1()
      /home/debian/.cache/act/37b13738279f9342/hostexecutor/act/container/host_environment.go:388
      +0x354

Previous read at 0x00c0008541d8 by goroutine 9328:
  code.forgejo.org/forgejo/runner/v11/act/container.(*ptyWriter).Write()
      /home/debian/.cache/act/37b13738279f9342/hostexecutor/act/container/host_environment.go:199 +0x57
  io.copyBuffer()
      /home/debian/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.24.7.linux-amd64/src/io/io.go:431
      +0x2ce

Goroutine 9324 (running) created at:
  code.forgejo.org/forgejo/runner/v11/act/runner.(*runnerImpl).NewPlanExecutor.func1.NewParallelExecutor.2()
      /home/debian/.cache/act/37b13738279f9342/hostexecutor/act/common/executor.go:105 +0x144
  code.forgejo.org/forgejo/runner/v11/act/runner.(*runnerImpl).NewPlanExecutor.func1.NewParallelExecutor.3.1()
      /home/debian/.cache/act/37b13738279f9342/hostexecutor/act/common/executor.go:107 +0x61
  code.forgejo.org/forgejo/runner/v11/act/runner.(*runnerImpl).NewPlanExecutor.func1.NewParallelExecutor.3.gowrap1()
      /home/debian/.cache/act/37b13738279f9342/hostexecutor/act/common/executor.go:109 +0x4f
Goroutine 9328 (running) created at:
  code.forgejo.org/forgejo/runner/v11/act/container.(*HostEnvironment).exec()
      /home/debian/.cache/act/37b13738279f9342/hostexecutor/act/container/host_environment.go:356 +0x112a
  code.forgejo.org/forgejo/runner/v11/act/runner.(*stepRun).main.func1.(*HostEnvironment).ExecWithCmdLine.1()
      /home/debian/.cache/act/37b13738279f9342/hostexecutor/act/container/host_environment.go:388 +0x354
  code.forgejo.org/forgejo/runner/v11/act/runner.(*stepRun).main.func1()
```
This commit is contained in:
Earl Warren 2025-09-15 17:17:44 +02:00
parent 6877142ba4
commit 69df253e41
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00

View file

@ -13,6 +13,7 @@ import (
"path/filepath"
"runtime"
"strings"
"sync/atomic"
"time"
"github.com/go-git/go-billy/v5/helper/polyfill"
@ -191,12 +192,12 @@ func (e *HostEnvironment) Start(_ bool) common.Executor {
type ptyWriter struct {
Out io.Writer
AutoStop bool
AutoStop atomic.Bool
dirtyLine bool
}
func (w *ptyWriter) Write(buf []byte) (int, error) {
if w.AutoStop && len(buf) > 0 && buf[len(buf)-1] == 4 {
if w.AutoStop.Load() && len(buf) > 0 && buf[len(buf)-1] == 4 {
n, err := w.Out.Write(buf[:len(buf)-1])
if err != nil {
return n, err
@ -365,7 +366,7 @@ func (e *HostEnvironment) exec(ctx context.Context, commandparam []string, cmdli
return fmt.Errorf("RUN %w", err)
}
if tty != nil {
writer.AutoStop = true
writer.AutoStop.Store(true)
if _, err := tty.Write([]byte("\x04")); err != nil {
common.Logger(ctx).Debug("Failed to write EOT")
}