Skip to content

Commit 84501b7

Browse files
authored
Merge pull request #265 from haiyanmeng/race
🐛 Avoid data race on package type data
2 parents e53fd19 + 954f926 commit 84501b7

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

pkg/loader/loader.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,18 @@ func (l *loader) typeCheck(pkg *Package) {
243243

244244
// The imports map is keyed by import path.
245245
importedPkg := pkg.Imports()[path]
246+
247+
// it's possible to have a call to check in parallel to a call to this
248+
// if one package in the package graph gets its dependency filtered out,
249+
// but another doesn't (so one wants a "dummy" package here, and another
250+
// wants the full check).
251+
//
252+
// Thus, we need to lock here (at least for the time being) to avoid
253+
// races between the above write to `pkg.Types` and this checking of
254+
// importedPkg.Types.
255+
importedPkg.Lock()
256+
defer importedPkg.Unlock()
257+
246258
if importedPkg == nil {
247259
return nil, fmt.Errorf("no package information for %q", path)
248260
}

0 commit comments

Comments
 (0)