Skip to content

Commit

Permalink
Fix unlikely data race when calling BaseExecutor methods
Browse files Browse the repository at this point in the history
Calling these methods defined on a value receiver copies the BaseExecutor
instance and could cause a data race if another goroutine is writing to it.
In practice this wasn't a problem and unlikely anyone would ever run into it on
master, but it did appear on the feat/1320-execution-api branch (#1863) when
running:

go run -race main.go run --quiet -u 5 -i 5 'github.com/k6io/k6/samples/http_get.js'

Clipped stack trace:

    WARNING: DATA RACE
    Write at 0x00c00050d7a8 by main goroutine:
      go.k6.io/k6/lib/executor.(*SharedIterations).Init()
          /home/ivan/Projects/k6io/k6/lib/executor/shared_iterations.go:179 +0x384
      go.k6.io/k6/core/local.(*ExecutionScheduler).Init()
          /home/ivan/Projects/k6io/k6/core/local/local.go:276 +0xc1c
      go.k6.io/k6/core.(*Engine).Init()
          /home/ivan/Projects/k6io/k6/core/engine.go:190 +0x148
      go.k6.io/k6/cmd.getRunCmd.func1()
          /home/ivan/Projects/k6io/k6/cmd/run.go:248 +0x1ad7
    ...

    Previous read at 0x00c00050d7a8 by goroutine 32:
      go.k6.io/k6/lib/executor.(*SharedIterations).GetProgress()
          <autogenerated>:1 +0x85
      go.k6.io/k6/cmd.getRunCmd.func1.1()
          /home/ivan/Projects/k6io/k6/cmd/run.go:180 +0x13d

Also see grafana/k6#1863 (comment) .
  • Loading branch information
Ivan Mirić committed Jun 21, 2021
1 parent af0cffe commit 1b23a52
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/executor/base_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,29 +79,29 @@ func (bs *BaseExecutor) Init(_ context.Context) error ***REMOVED***
***REMOVED***

// GetConfig returns the configuration with which this executor was launched.
func (bs BaseExecutor) GetConfig() lib.ExecutorConfig ***REMOVED***
func (bs *BaseExecutor) GetConfig() lib.ExecutorConfig ***REMOVED***
return bs.config
***REMOVED***

// getNextLocalVUID increments and returns the next VU ID that's specific for
// this executor (i.e. not global like __VU).
func (bs BaseExecutor) getNextLocalVUID() uint64 ***REMOVED***
func (bs *BaseExecutor) getNextLocalVUID() uint64 ***REMOVED***
return atomic.AddUint64(bs.VUIDLocal, 1)
***REMOVED***

// GetLogger returns the executor logger entry.
func (bs BaseExecutor) GetLogger() *logrus.Entry ***REMOVED***
func (bs *BaseExecutor) GetLogger() *logrus.Entry ***REMOVED***
return bs.logger
***REMOVED***

// GetProgress just returns the progressbar pointer.
func (bs BaseExecutor) GetProgress() *pb.ProgressBar ***REMOVED***
func (bs *BaseExecutor) GetProgress() *pb.ProgressBar ***REMOVED***
return bs.progress
***REMOVED***

// getMetricTags returns a tag set that can be used to emit metrics by the
// executor. The VU ID is optional.
func (bs BaseExecutor) getMetricTags(vuID *uint64) *stats.SampleTags ***REMOVED***
func (bs *BaseExecutor) getMetricTags(vuID *uint64) *stats.SampleTags ***REMOVED***
tags := bs.executionState.Options.RunTags.CloneTags()
if bs.executionState.Options.SystemTags.Has(stats.TagScenario) ***REMOVED***
tags["scenario"] = bs.config.GetName()
Expand Down

0 comments on commit 1b23a52

Please sign in to comment.