Skip to content

Commit 5c48811

Browse files
chenzhongtaorsc
authored andcommitted
[release-branch.go1.9] cmd/compile: limit the number of simultaneously opened files to avoid EMFILE/ENFILE errors
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-on: https://go-review.googlesource.com/63752 Run-TryBot: Russ Cox <[email protected]>
1 parent 8c7fa95 commit 5c48811

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

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

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package gc
77
import (
88
"fmt"
99
"os"
10+
"runtime"
1011
"strconv"
1112
"strings"
1213
"unicode/utf8"
@@ -20,12 +21,16 @@ import (
2021
func parseFiles(filenames []string) uint {
2122
var lines uint
2223
var noders []*noder
24+
// Limit the number of simultaneously open files.
25+
sem := make(chan struct{}, runtime.GOMAXPROCS(0)+10)
2326

2427
for _, filename := range filenames {
2528
p := &noder{err: make(chan syntax.Error)}
2629
noders = append(noders, p)
2730

2831
go func(filename string) {
32+
sem <- struct{}{}
33+
defer func() { <-sem }()
2934
defer close(p.err)
3035
base := src.NewFileBase(filename, absFilename(filename))
3136

0 commit comments

Comments
 (0)