Commit 99414a5b authored by zhongtao.chen's avatar zhongtao.chen Committed by Ian Lance Taylor

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 <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent 2a2e4dad
...@@ -7,6 +7,7 @@ package gc ...@@ -7,6 +7,7 @@ package gc
import ( import (
"fmt" "fmt"
"os" "os"
"runtime"
"strconv" "strconv"
"strings" "strings"
"unicode/utf8" "unicode/utf8"
...@@ -20,12 +21,16 @@ import ( ...@@ -20,12 +21,16 @@ import (
func parseFiles(filenames []string) uint { func parseFiles(filenames []string) uint {
var lines uint var lines uint
var noders []*noder var noders []*noder
// Limit the number of simultaneously open files.
sem := make(chan struct{}, runtime.GOMAXPROCS(0)+10)
for _, filename := range filenames { for _, filename := range filenames {
p := &noder{err: make(chan syntax.Error)} p := &noder{err: make(chan syntax.Error)}
noders = append(noders, p) noders = append(noders, p)
go func(filename string) { go func(filename string) {
sem <- struct{}{}
defer func() { <-sem }()
defer close(p.err) defer close(p.err)
base := src.NewFileBase(filename, absFilename(filename)) base := src.NewFileBase(filename, absFilename(filename))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment