-
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
linter: loopvarcapture should check interface methods #102679
Conversation
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: cockroachdb#102678 Release note: None [1] cockroachdb#84867 (comment)
First attempt failed [1], [2], as expected (since it didn't include the fix to
[1] https://teamcity.cockroachdb.com/buildConfiguration/Cockroach_Ci_Tests_UnusedLint/9890552 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the investigation and fix! I have a vague memory of using StaticCallee
over Callee
, but the latter makes more sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 5 of 5 files at r1, all commit messages.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @smg260)
TFTR! bors r=renatolabs,herkolategan |
Build succeeded: |
The
loopvarcapture
linter is part ofroachvet
. 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 viaGoRoutineFunctions
.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)