Skip to content

test: Fix data race in loadtest/reconnectingpty #5431

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

Merged
merged 1 commit into from
Dec 15, 2022

Conversation

mafredri
Copy link
Member

@mafredri mafredri commented Dec 15, 2022

There is a data race in loadtest/reconnectingpty where the goroutine created by copyContext is left behind and producing writes after Run has exited. Tests use simple bytes.Buffer and reading it is unsafe.

This PR fixes the data race:

==================
WARNING: DATA RACE
Write at 0x00c001b2c990 by goroutine 358:
  bytes.(*Buffer).tryGrowByReslice()
      C:/Program Files/Go/src/bytes/buffer.go:108 +0xb3
  bytes.(*Buffer).Write()
      C:/Program Files/Go/src/bytes/buffer.go:168 +0x18
  github.com/coder/coder/loadtest/loadtestutil.(*SyncWriter).Write()
      C:/Users/ZeroCool/Downloads/coder/loadtest/loadtestutil/syncwriter.go:25 +0x121
  github.com/coder/coder/loadtest/reconnectingpty.copyContext.func1()
      C:/Users/ZeroCool/Downloads/coder/loadtest/reconnectingpty/run.go:119 +0x24a

Previous read at 0x00c001b2c990 by goroutine 27:
  bytes.(*Buffer).String()
      C:/Program Files/Go/src/bytes/buffer.go:65 +0x294
  github.com/coder/coder/loadtest/reconnectingpty_test.Test_Runner.func3.2()
      C:/Users/ZeroCool/Downloads/coder/loadtest/reconnectingpty/run_test.go:125 +0x274
  testing.tRunner()
      C:/Program Files/Go/src/testing/testing.go:1446 +0x216
  testing.(*T).Run.func1()
      C:/Program Files/Go/src/testing/testing.go:1493 +0x47

@mafredri mafredri marked this pull request as ready for review December 15, 2022 12:03
Copy link
Member

@deansheather deansheather left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool solution and seems robust to me

@deansheather
Copy link
Member

test: doesn't seem like a valid PR prefix though, shouldn't it be fix or chore

@mafredri mafredri merged commit 4bc420d into main Dec 15, 2022
@mafredri mafredri deleted the mafredri/fix-loadtest-data-race branch December 15, 2022 13:06
@github-actions github-actions bot locked and limited conversation to collaborators Dec 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants