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
x/tools/imports: TestLocalPrefix is racy #25030
Comments
|
Thanks for flagging. Given the nature of the change, I highly doubt that the change in |
Confirmed that this race is preexisting.
Now, run tests with race:
|
The race is occurring here: // Find candidate packages, looking only at their directory names first.
var candidates []*pkg
for _, pkg := range dirScan {
if pkgIsCandidate(filename, pkgName, pkg) {
pkg.distance = distance(pkgDir, pkg.dir)
candidates = append(candidates, pkg)
}
} I believe the issue is that This may be naïve, but protecting that assignment using // Find candidate packages, looking only at their directory names first.
var candidates []*pkg
for _, pkg := range dirScan {
if pkgIsCandidate(filename, pkgName, pkg) {
pkgDistance := distance(pkgDir, pkg.dir)
dirScanMu.Lock()
pkg.distance = pkgDistance
dirScanMu.Unlock()
candidates = append(candidates, pkg)
}
} @bradfitz any thoughts on this? |
I think the problem is deeper than that: It's not at all obvious to me whether we run two of those concurrency, but the fact that it's not locally obvious suggests that we shouldn't rely on it either way. |
I can't resist a good concurrency puzzle. I'll send a fix. |
Change https://golang.org/cl/109156 mentions this issue: |
Checking out
c1def519f03ddf76f16b3e444ee1095d73afa01b
and running:The text was updated successfully, but these errors were encountered: