Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/tools/gopls: dynamic configuration overwrites env in multi-workspace sessions #39592

Open
findleyr opened this issue Jun 15, 2020 · 0 comments
Open
Labels
Milestone

Comments

@findleyr
Copy link

@findleyr findleyr commented Jun 15, 2020

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 into session.NewView. By passing around the session.options.UserOptions.Env slice, each view can end up mutating the same underlying array when appending to the slice during fetchConfig.

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

@gopherbot gopherbot added this to the Unreleased milestone Jun 15, 2020
@stamblerre stamblerre modified the milestones: Unreleased, gopls/v0.5.0 Jun 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.