Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unlikely data race when calling BaseExecutor methods #2067

Merged
merged 1 commit into from
Jun 16, 2021

Conversation

imiric
Copy link
Contributor

@imiric imiric commented Jun 16, 2021

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 #1863 (comment) .

(I didn't base this on master as I would need to rebase #1863 again and we all dislike the GH reference spam in issues 😅, and I would have to do this on #1863 anyway for the newly added methods.)

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 #1863 (comment) .
@imiric imiric merged commit f9e0ab6 into feat/1320-execution-api Jun 16, 2021
@imiric imiric deleted the fix/progress-data-race branch June 16, 2021 15:16
@na-- na-- added this to the v0.33.0 milestone Jun 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants