1
0
mirror of https://github.com/golang/go synced 2024-11-17 03:14:50 -07:00

cmd/compile: fix deadlock on syntax error

Fixes #52127

Change-Id: I6523c83350cb9263d23e3e8b472fe63a5cc99c2e
Reviewed-on: https://go-review.googlesource.com/c/go/+/398014
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Trust: Cherry Mui <cherryyz@google.com>
This commit is contained in:
hopehook 2022-04-04 23:01:16 +08:00 committed by Gopher Robot
parent c451a02a6d
commit 5a90270d7f

View File

@ -33,30 +33,35 @@ func LoadPackage(filenames []string) {
sem := make(chan struct{}, runtime.GOMAXPROCS(0)+10)
noders := make([]*noder, len(filenames))
for i, filename := range filenames {
for i := range noders {
p := noder{
err: make(chan syntax.Error),
}
noders[i] = &p
filename := filename
go func() {
sem <- struct{}{}
defer func() { <-sem }()
defer close(p.err)
fbase := syntax.NewFileBase(filename)
f, err := os.Open(filename)
if err != nil {
p.error(syntax.Error{Msg: err.Error()})
return
}
defer f.Close()
p.file, _ = syntax.Parse(fbase, f, p.error, p.pragma, mode) // errors are tracked via p.error
}()
}
go func() {
for i, filename := range filenames {
filename := filename
p := noders[i]
sem <- struct{}{}
go func() {
defer func() { <-sem }()
defer close(p.err)
fbase := syntax.NewFileBase(filename)
f, err := os.Open(filename)
if err != nil {
p.error(syntax.Error{Msg: err.Error()})
return
}
defer f.Close()
p.file, _ = syntax.Parse(fbase, f, p.error, p.pragma, mode) // errors are tracked via p.error
}()
}
}()
var lines uint
for _, p := range noders {
for e := range p.err {