Skip to content

Commit

Permalink
Merge pull request #265 from haiyanmeng/race
Browse files Browse the repository at this point in the history
🐛 Avoid data race on package type data
  • Loading branch information
k8s-ci-robot authored Jul 19, 2019
2 parents e53fd19 + 954f926 commit 84501b7
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,18 @@ func (l *loader) typeCheck(pkg *Package) {

// The imports map is keyed by import path.
importedPkg := pkg.Imports()[path]

// it's possible to have a call to check in parallel to a call to this
// if one package in the package graph gets its dependency filtered out,
// but another doesn't (so one wants a "dummy" package here, and another
// wants the full check).
//
// Thus, we need to lock here (at least for the time being) to avoid
// races between the above write to `pkg.Types` and this checking of
// importedPkg.Types.
importedPkg.Lock()
defer importedPkg.Unlock()

if importedPkg == nil {
return nil, fmt.Errorf("no package information for %q", path)
}
Expand Down

0 comments on commit 84501b7

Please sign in to comment.