You've already forked woodpecker
mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2026-06-03 16:35:37 +02:00
Fix race in pipeline runtime (#6451)
as step tracer is also used to update workflow environment variables
This commit is contained in:
@@ -16,6 +16,7 @@ package runtime
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
"github.com/oklog/ulid/v2"
|
||||
"github.com/rs/zerolog"
|
||||
@@ -43,6 +44,7 @@ type Runtime struct {
|
||||
ctx context.Context
|
||||
|
||||
tracer tracing.Tracer
|
||||
tracerLock sync.Mutex
|
||||
logger logging.Logger
|
||||
|
||||
taskUUID string
|
||||
@@ -58,6 +60,7 @@ func New(spec *backend_types.Config, backend backend_types.Backend, opts ...Opti
|
||||
r.engine = backend
|
||||
r.ctx = context.Background()
|
||||
r.taskUUID = ulid.Make().String()
|
||||
r.tracerLock = sync.Mutex{}
|
||||
for _, opt := range opts {
|
||||
opt(r)
|
||||
}
|
||||
|
||||
@@ -253,6 +253,10 @@ func (r *Runtime) traceStep(processState *backend_types.State, err error, step *
|
||||
// processState == nil && err == nil: step just started, leave s.CurrStepState zero-valued.
|
||||
}
|
||||
|
||||
// The tracer should just trace changes, but it currently also updates step env vars used in various ways:
|
||||
// https://github.com/woodpecker-ci/woodpecker/blob/main/agent/tracer.go#L79-L86 .
|
||||
r.tracerLock.Lock()
|
||||
defer r.tracerLock.Unlock()
|
||||
if traceErr := r.tracer.Trace(s); traceErr != nil {
|
||||
return traceErr
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user