From d25f9066828099517056ecb554d8d0b84f026ddd Mon Sep 17 00:00:00 2001 From: Karthik Nayak Date: Thu, 17 Jun 2021 19:13:30 +0000 Subject: [PATCH] internal/lsp: do not block on channel when there is an error In `internal/lsp/cmd.(*connection).diagnoseFiles`, when we request for `gopls/diagnoseFiles`, we are blocked on the channel even if there is an error. In such a scenario, we've reach a deadlock since. Avoid this by checking for error, existing if it exists and also closing the channel while we're at it. Fixes golang/go#46251 Signed-off-by: Karthik Nayak Change-Id: I4266ab3ac272a9ae3eac2084b70b6568b72c1984 GitHub-Last-Rev: 94bf2926a0f35d51d62643618a8072ef5a8b5225 GitHub-Pull-Request: golang/tools#324 Reviewed-on: https://go-review.googlesource.com/c/tools/+/329109 Reviewed-by: Rebecca Stambler Trust: Rebecca Stambler Trust: Heschi Kreinick Run-TryBot: Rebecca Stambler gopls-CI: kokoro TryBot-Result: Go Bot --- internal/lsp/cmd/cmd.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/lsp/cmd/cmd.go b/internal/lsp/cmd/cmd.go index 1acf197d0de..ad344f7e560 100644 --- a/internal/lsp/cmd/cmd.go +++ b/internal/lsp/cmd/cmd.go @@ -527,8 +527,13 @@ func (c *connection) diagnoseFiles(ctx context.Context, files []span.URI) error c.Client.diagnosticsDone = make(chan struct{}) _, err := c.Server.NonstandardRequest(ctx, "gopls/diagnoseFiles", map[string]interface{}{"files": untypedFiles}) + if err != nil { + close(c.Client.diagnosticsDone) + return err + } + <-c.Client.diagnosticsDone - return err + return nil } func (c *connection) terminate(ctx context.Context) {