go/loader: limit concurrency of I/O operations during parsing
This is a putative fix for the file descriptor exhaustion problem described in https://github.com/golang/go/issues/10306. Change-Id: If603fb9bbaec1b53f6b44d15b2c202e4670035ce Reviewed-on: https://go-review.googlesource.com/8421 Reviewed-by: Matt Joiner <anacrolix@gmail.com> Reviewed-by: David Crawshaw <crawshaw@golang.org>
This commit is contained in:
parent
a18bb1d557
commit
8a9ac1b806
|
|
@ -17,6 +17,10 @@ import (
|
||||||
"golang.org/x/tools/go/buildutil"
|
"golang.org/x/tools/go/buildutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// We use a counting semaphore to limit
|
||||||
|
// the number of parallel I/O calls per process.
|
||||||
|
var sema = make(chan bool, 10)
|
||||||
|
|
||||||
// parseFiles parses the Go source files within directory dir and
|
// parseFiles parses the Go source files within directory dir and
|
||||||
// returns the ASTs of the ones that could be at least partially parsed,
|
// returns the ASTs of the ones that could be at least partially parsed,
|
||||||
// along with a list of I/O and parse errors encountered.
|
// along with a list of I/O and parse errors encountered.
|
||||||
|
|
@ -38,7 +42,11 @@ func parseFiles(fset *token.FileSet, ctxt *build.Context, displayPath func(strin
|
||||||
}
|
}
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func(i int, file string) {
|
go func(i int, file string) {
|
||||||
defer wg.Done()
|
sema <- true // wait
|
||||||
|
defer func() {
|
||||||
|
wg.Done()
|
||||||
|
<-sema // signal
|
||||||
|
}()
|
||||||
var rd io.ReadCloser
|
var rd io.ReadCloser
|
||||||
var err error
|
var err error
|
||||||
if ctxt.OpenFile != nil {
|
if ctxt.OpenFile != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue