mirror of
https://github.com/golang/go
synced 2024-11-18 14:14:46 -07:00
internal/lsp: prevent too much open files issues
On MacOS the default open file limit is 256 files per process. For big projects this could cause issues when reading all files (more or less) at the same time. By moving up the `parseLimit` so the reading of the file is only done when it is allowed to start parsing the file, we stay well below the 256 files per process (as the `parseLimit` is currently set to 20). Since `parseLimit` is actually only used to limit IO access, let's also rename the const to `parseLimit`. Change-Id: Ie8744030875d84d0d6095ee4ec2d9d553911bed1 Reviewed-on: https://go-review.googlesource.com/c/tools/+/189437 Reviewed-by: Rebecca Stambler <rstambler@golang.org> Run-TryBot: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
parent
b346f7fd45
commit
128824a23e
10
internal/lsp/cache/parse.go
vendored
10
internal/lsp/cache/parse.go
vendored
@ -18,8 +18,8 @@ import (
|
|||||||
errors "golang.org/x/xerrors"
|
errors "golang.org/x/xerrors"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Limits the number of parallel parser calls per process.
|
// Limits the number of parallel file reads per process.
|
||||||
var parseLimit = make(chan struct{}, 20)
|
var ioLimit = make(chan struct{}, 20)
|
||||||
|
|
||||||
// parseKey uniquely identifies a parsed Go file.
|
// parseKey uniquely identifies a parsed Go file.
|
||||||
type parseKey struct {
|
type parseKey struct {
|
||||||
@ -77,12 +77,14 @@ func (h *parseGoHandle) Parse(ctx context.Context) (*ast.File, error) {
|
|||||||
func parseGo(ctx context.Context, c *cache, fh source.FileHandle, mode source.ParseMode) (*ast.File, error) {
|
func parseGo(ctx context.Context, c *cache, fh source.FileHandle, mode source.ParseMode) (*ast.File, error) {
|
||||||
ctx, done := trace.StartSpan(ctx, "cache.parseGo", telemetry.File.Of(fh.Identity().URI.Filename()))
|
ctx, done := trace.StartSpan(ctx, "cache.parseGo", telemetry.File.Of(fh.Identity().URI.Filename()))
|
||||||
defer done()
|
defer done()
|
||||||
|
|
||||||
|
ioLimit <- struct{}{}
|
||||||
buf, _, err := fh.Read(ctx)
|
buf, _, err := fh.Read(ctx)
|
||||||
|
<-ioLimit // Make sure to release the token, even when an error is returned.
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
parseLimit <- struct{}{}
|
|
||||||
defer func() { <-parseLimit }()
|
|
||||||
parserMode := parser.AllErrors | parser.ParseComments
|
parserMode := parser.AllErrors | parser.ParseComments
|
||||||
if mode == source.ParseHeader {
|
if mode == source.ParseHeader {
|
||||||
parserMode = parser.ImportsOnly | parser.ParseComments
|
parserMode = parser.ImportsOnly | parser.ParseComments
|
||||||
|
3
internal/lsp/cache/view.go
vendored
3
internal/lsp/cache/view.go
vendored
@ -509,7 +509,8 @@ func (v *view) findFile(uri span.URI) (viewFile, error) {
|
|||||||
pathStat, err := os.Stat(fname)
|
pathStat, err := os.Stat(fname)
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else if err != nil {
|
}
|
||||||
|
if err != nil {
|
||||||
return nil, nil // the file may exist, return without an error
|
return nil, nil // the file may exist, return without an error
|
||||||
}
|
}
|
||||||
for _, c := range candidates {
|
for _, c := range candidates {
|
||||||
|
Loading…
Reference in New Issue
Block a user