Skip to content

Commit

Permalink
internal/lsp: do not block on channel when there is an error
Browse files Browse the repository at this point in the history
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 <karthik.188@gmail.com>

Change-Id: I4266ab3ac272a9ae3eac2084b70b6568b72c1984
GitHub-Last-Rev: 94bf292
GitHub-Pull-Request: #324
Reviewed-on: https://go-review.googlesource.com/c/tools/+/329109
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
  • Loading branch information
KarthikNayak authored and stamblerre committed Jun 18, 2021
1 parent 463a76b commit d25f906
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion internal/lsp/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit d25f906

Please sign in to comment.