mirror of
https://github.com/golang/go
synced 2024-10-01 01:38:33 -06:00
go/loader: fix fd leak and limit calls to ioutil.ReadDir
This makes 'ulimit -n 128; go test -short -v' pass. It did not before, and that was breaking the openbsd/386 builder. For golang/go#11811. Change-Id: Idfdb2f4007ed06c6084486c0e58a561add552d2c Reviewed-on: https://go-review.googlesource.com/13695 Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
parent
9f2124fb70
commit
93604a3dc2
@ -87,9 +87,9 @@ func processCgoFiles(bp *build.Package, fset *token.FileSet, DisplayPath func(pa
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rd.Close()
|
||||
display := filepath.Join(bp.Dir, cgoDisplayFiles[i])
|
||||
f, err := parser.ParseFile(fset, display, rd, mode)
|
||||
rd.Close()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -449,7 +449,9 @@ func (conf *Config) Load() (*Program, error) {
|
||||
conf.FindPackage = func(ctxt *build.Context, path string) (*build.Package, error) {
|
||||
// TODO(adonovan): cache calls to build.Import
|
||||
// so we don't do it three times per test package.
|
||||
ioLimit <- true
|
||||
bp, err := ctxt.Import(path, conf.Cwd, 0)
|
||||
<-ioLimit
|
||||
if _, ok := err.(*build.NoGoError); ok {
|
||||
return bp, nil // empty directory is not an error
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ import (
|
||||
|
||||
// We use a counting semaphore to limit
|
||||
// the number of parallel I/O calls per process.
|
||||
var sema = make(chan bool, 10)
|
||||
var ioLimit = make(chan bool, 10)
|
||||
|
||||
// parseFiles parses the Go source files within directory dir and
|
||||
// returns the ASTs of the ones that could be at least partially parsed,
|
||||
@ -42,10 +42,10 @@ func parseFiles(fset *token.FileSet, ctxt *build.Context, displayPath func(strin
|
||||
}
|
||||
wg.Add(1)
|
||||
go func(i int, file string) {
|
||||
sema <- true // wait
|
||||
ioLimit <- true // wait
|
||||
defer func() {
|
||||
wg.Done()
|
||||
<-sema // signal
|
||||
<-ioLimit // signal
|
||||
}()
|
||||
var rd io.ReadCloser
|
||||
var err error
|
||||
|
Loading…
Reference in New Issue
Block a user