mirror of
https://github.com/netbirdio/easyjson.git
synced 2026-05-22 18:44:42 -07:00
Fixes a concurrency issue with go module package path cache
The `chromedp-gen` tool, which makes use of the raw code, always encounters issues with slow builds. This adds a simple `sync.RWMutex` to the Go module map package path cache variable that's causing problems.
This commit is contained in:
+14
-6
@@ -90,19 +90,27 @@ func getPkgPathFromGoMod(fname string, isDir bool, goModPath string) (string, er
|
||||
return path.Clean(rel), nil
|
||||
}
|
||||
|
||||
var (
|
||||
modulePrefix = []byte("\nmodule ")
|
||||
pkgPathFromGoModCache = make(map[string]string)
|
||||
)
|
||||
var modulePrefix = []byte("\nmodule ")
|
||||
|
||||
var pkgPathFromGoModCache = struct {
|
||||
paths map[string]string
|
||||
sync.RWMutex
|
||||
}{
|
||||
paths: make(map[string]string),
|
||||
}
|
||||
|
||||
func getModulePath(goModPath string) string {
|
||||
pkgPath, ok := pkgPathFromGoModCache[goModPath]
|
||||
pkgPathFromGoModCache.RLock()
|
||||
pkgPath, ok := pkgPathFromGoModCache.paths[goModPath]
|
||||
pkgPathFromGoModCache.RUnlock()
|
||||
if ok {
|
||||
return pkgPath
|
||||
}
|
||||
|
||||
defer func() {
|
||||
pkgPathFromGoModCache[goModPath] = pkgPath
|
||||
pkgPathFromGoModCache.Lock()
|
||||
pkgPathFromGoModCache.paths[goModPath] = pkgPath
|
||||
pkgPathFromGoModCache.Unlock()
|
||||
}()
|
||||
|
||||
data, err := ioutil.ReadFile(goModPath)
|
||||
|
||||
Reference in New Issue
Block a user