symbols: avoid spamming handleParseRequest on context cancelation (#61732)

Understanding how Parse works (and its callers) with respect to
goroutines and channels is a sure path to the asylum. This is a short
term fix around how it behaves when the context is canceled.

From what I can tell we can have a large number of parse requests go
through handleParseRequest even once the context has been canceled,
leading to large amounts of logging of errors which all amount to
context canceled. This is a short term fix which drains the channel if
we know we are just gonna fail our call to handleParseRequest.

Test Plan: go test. Didn't manual test, but the code change is minor
enough that I trust it (famous last words).
This commit is contained in:
Keegan Carruthers-Smith 2024-04-11 09:27:11 +02:00 committed by GitHub
parent f674124ec1
commit a0b74fb665
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -115,6 +115,12 @@ func (p *parser) Parse(ctx context.Context, args search.SymbolsParameters, paths
break
}
// Drain channel if our context has been canceled. Otherwise
// we just logspam on handleParseRequest.
if ctx.Err() != nil {
continue
}
atomic.AddUint32(&totalRequests, 1)
if err := p.handleParseRequest(ctx, symbolOrErrors, parseRequestOrError.ParseRequest, &totalSymbols); err != nil {
log15.Error("error handling parse request", "error", err, "path", parseRequestOrError.ParseRequest.Path)