1
0
mirror of https://github.com/golang/go synced 2024-11-18 19:54:44 -07: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:
Russ Cox 2015-08-18 13:24:30 -04:00
parent 9f2124fb70
commit 93604a3dc2
3 changed files with 6 additions and 4 deletions

View File

@ -87,9 +87,9 @@ func processCgoFiles(bp *build.Package, fset *token.FileSet, DisplayPath func(pa
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer rd.Close()
display := filepath.Join(bp.Dir, cgoDisplayFiles[i]) display := filepath.Join(bp.Dir, cgoDisplayFiles[i])
f, err := parser.ParseFile(fset, display, rd, mode) f, err := parser.ParseFile(fset, display, rd, mode)
rd.Close()
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -449,7 +449,9 @@ func (conf *Config) Load() (*Program, error) {
conf.FindPackage = func(ctxt *build.Context, path string) (*build.Package, error) { conf.FindPackage = func(ctxt *build.Context, path string) (*build.Package, error) {
// TODO(adonovan): cache calls to build.Import // TODO(adonovan): cache calls to build.Import
// so we don't do it three times per test package. // so we don't do it three times per test package.
ioLimit <- true
bp, err := ctxt.Import(path, conf.Cwd, 0) bp, err := ctxt.Import(path, conf.Cwd, 0)
<-ioLimit
if _, ok := err.(*build.NoGoError); ok { if _, ok := err.(*build.NoGoError); ok {
return bp, nil // empty directory is not an error return bp, nil // empty directory is not an error
} }

View File

@ -19,7 +19,7 @@ import (
// We use a counting semaphore to limit // We use a counting semaphore to limit
// the number of parallel I/O calls per process. // 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 // 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,
@ -42,10 +42,10 @@ 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) {
sema <- true // wait ioLimit <- true // wait
defer func() { defer func() {
wg.Done() wg.Done()
<-sema // signal <-ioLimit // signal
}() }()
var rd io.ReadCloser var rd io.ReadCloser
var err error var err error