]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1.9] cmd/compile: limit the number of simultaneously opened files...
authorzhongtao.chen <chenzhongtao@126.com>
Tue, 22 Aug 2017 02:33:10 +0000 (10:33 +0800)
committerRuss Cox <rsc@golang.org>
Wed, 25 Oct 2017 20:22:53 +0000 (20:22 +0000)
If the Go packages with enough source files,it will cause EMFILE/ENFILE error,
Fix this by limiting the number of simultaneously opened files.

Fixes #21621

Change-Id: I8555d79242d2f90771e37e073b7540fc7194a64a
Reviewed-on: https://go-review.googlesource.com/57751
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-on: https://go-review.googlesource.com/63752
Run-TryBot: Russ Cox <rsc@golang.org>

src/cmd/compile/internal/gc/noder.go

index 5f199482222ee9f906c356aefc9afeaa64e1fa1b..7a1ea2707c60bfbaec563d5a456a8c2c0c78795e 100644 (file)
@@ -7,6 +7,7 @@ package gc
 import (
        "fmt"
        "os"
+       "runtime"
        "strconv"
        "strings"
        "unicode/utf8"
@@ -20,12 +21,16 @@ import (
 func parseFiles(filenames []string) uint {
        var lines uint
        var noders []*noder
+       // Limit the number of simultaneously open files.
+       sem := make(chan struct{}, runtime.GOMAXPROCS(0)+10)
 
        for _, filename := range filenames {
                p := &noder{err: make(chan syntax.Error)}
                noders = append(noders, p)
 
                go func(filename string) {
+                       sem <- struct{}{}
+                       defer func() { <-sem }()
                        defer close(p.err)
                        base := src.NewFileBase(filename, absFilename(filename))