x/tools/gopls: dynamic configuration overwrites env in multi-workspace sessions #39592
Labels
FrozenDueToAge
gopls
Issues related to the Go language server, gopls.
Tools
This label describes issues relating to any tools in the x/tools repository.
Milestone
There are several places in the gopls codebase that assume a source.Options may be cloned by passing it by value. Perhaps this was once correct, but isn't correct anymore, as for example
UserOptions.Env
is a slice.One place where this shows up is in
addView
, which calls session.Options() and then passes that intosession.NewView
. By passing around thesession.options.UserOptions.Env
slice, each view can end up mutating the same underlying array when appending to the slice duringfetchConfig
.Another place this manifests is in didChangeConfiguration. This
fetchConfig
call, which is supposed to just fetch the new view options, actually mutates the existing view options:https://cs.opensource.google/go/tools/+/master:internal/lsp/workspace.go;l=49;drc=9778d966fa8150a8a0027e8169749bae53a2ee86
Later on, we check if there were any major changes, and fail to detect a UserOptions.Env change:
https://cs.opensource.google/go/tools/+/master:internal/lsp/cache/view.go;l=191;drc=9001f16f58f90e85dd6b3c2b727e3ba0d4f85838
We should explictly clone source.Options before mutating it. Note this would also make it safe to pass around the (quite large) options type by reference, and/or make it opaque.
cc @stamblerre @heschik
The text was updated successfully, but these errors were encountered: