-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
loopvarcapture linter should check interface methods #102678
Comments
srosenberg
added
C-bug
Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.
A-testing
Testing tools and infrastructure
labels
May 1, 2023
cc @cockroachdb/test-eng |
After instrumenting the linter to print matched Build
|
for i := nodes; i <= nodes*maxPerNodeConcurrency; i += nodes { | |
c.Wipe(ctx, c.Range(1, nodes)) | |
c.Start(ctx, t.L(), option.DefaultStartOpts(), install.MakeClusterSettings(), c.Range(1, nodes)) | |
t.Status("running workload") | |
m := c.NewMonitor(ctx, c.Range(1, nodes)) | |
m.Go(func(ctx context.Context) error { | |
cmd := fmt.Sprintf("./workload run kv --init --read-percent=%d "+ | |
"--splits=1000 --duration=1m "+fmt.Sprintf("--concurrency=%d", i)+ |
craig bot
pushed a commit
that referenced
this issue
May 11, 2023
102679: linter: loopvarcapture should check interface methods r=renatolabs,herkolategan a=srosenberg The `loopvarcapture` linter is part of `roachvet`. It flags incorrect uses of loop variables captured by reference in Go routines or defer statements--a common source of data races. In addition to checking Go routines created via the `go` keyword, the linter also checks against other (internal) APIs, which are known to create Go routines; this is specified via `GoRoutineFunctions`. An existing bug prevented the linter from checking inside `Monitor.Go`, which are commonly used inside roachtests. This PR fixes the linter bug as well as the pre-existing bug inside a roachtest, which this linter now detects. This PR also removes the uncessary hack, i.e., `RunDespiteErrors`, introduced in [1]. By allowing the type checker to swallow errors, the test was susceptible to silent errors, e.g., buggy testdata. Instead, we work around by disabling CGO. Epic: none Fixes: #102678 Release note: None [1] #84867 (comment) Co-authored-by: Stan Rosenberg <[email protected]>
blathers-crl bot
pushed a commit
that referenced
this issue
May 11, 2023
The `loopvarcapture` linter is part of `roachvet`. It flags incorrect uses of loop variables captured by reference in Go routines or defer statements--a common source of data races. In addition to checking Go routines created via the `go` keyword, the linter also checks against other (internal) APIs, which are known to create Go routines; this is specified via `GoRoutineFunctions`. An existing bug prevented the linter from checking inside `Monitor.Go`, which are commonly used inside roachtests. This PR fixes the linter bug as well as the pre-existing bug inside a roachtest, which this linter now detects. This PR also removes the uncessary hack, i.e., `RunDespiteErrors`, introduced in [1]. By allowing the type checker to swallow errors, the test was susceptible to silent errors, e.g., buggy testdata. Instead, we work around by disabling CGO. Epic: none Fixes: #102678 Release note: None [1] #84867 (comment)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The existing implementation of the
loopvarcapture
linter [1] incorrectly omits all checks insideMonitor.Go
[2]. This was a fairly random discovery. I was performing a manual inspection of the output of the go compiler, using-gcflags="-m=2"
. Surprisingly, I noticed the following diagnostic message. Upon closer inspection, it's indeed a bug which was supposed to be flagged by theloopvarcapture
linter.The root cause is restricting callees (of
Go
variants) to be non-interface methods. The callee in [2] happens to be an interface method.[1] #80803
[2]
cockroach/pkg/testutils/lint/passes/loopvarcapture/loopvarcapture.go
Line 68 in ede4f45
Jira issue: CRDB-27587
The text was updated successfully, but these errors were encountered: