Skip to content

Commit 23787c0

Browse files
committed
internal/lsp: fix race condition in diagnostics show message
Detected on CL 263984. Logs: https://storage.googleapis.com/go-build-log/62f18d07/linux-amd64-race_c6e9f2a0.log. Change-Id: I07deb768eea43a277d67fbe72cabed885af41b93 Reviewed-on: https://go-review.googlesource.com/c/tools/+/264202 Trust: Rebecca Stambler <[email protected]> Run-TryBot: Rebecca Stambler <[email protected]> gopls-CI: kokoro <[email protected]> Reviewed-by: Heschi Kreinick <[email protected]> TryBot-Result: Go Bot <[email protected]>
1 parent 6652d1f commit 23787c0

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

internal/lsp/diagnostics.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,9 @@ If you believe this is a mistake, please file an issue: https://github.com/golan
206206
return nil, nil
207207
}
208208
var (
209-
showMsg *protocol.ShowMessageParams
210-
wg sync.WaitGroup
209+
showMsgMu sync.Mutex
210+
showMsg *protocol.ShowMessageParams
211+
wg sync.WaitGroup
211212
)
212213
for _, pkg := range wsPkgs {
213214
wg.Add(1)
@@ -236,10 +237,12 @@ If you believe this is a mistake, please file an issue: https://github.com/golan
236237
// Check if might want to warn the user about their build configuration.
237238
// Our caller decides whether to send the message.
238239
if warn && !snapshot.ValidBuildConfiguration() {
240+
showMsgMu.Lock()
239241
showMsg = &protocol.ShowMessageParams{
240242
Type: protocol.Warning,
241243
Message: `You are neither in a module nor in your GOPATH. If you are using modules, please open your editor to a directory in your module. If you believe this warning is incorrect, please file an issue: https://github.com/golang/go/issues/new.`,
242244
}
245+
showMsgMu.Unlock()
243246
}
244247
if err != nil {
245248
event.Error(ctx, "warning: diagnose package", err, tag.Snapshot.Of(snapshot.ID()), tag.Package.Of(pkg.ID()))

0 commit comments

Comments
 (0)