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

findleyr opened this issue Jun 15, 2020 · 1 comment


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:;l=49;drc=9778d966fa8150a8a0027e8169749bae53a2ee86
Later on, we check if there were any major changes, and fail to detect a UserOptions.Env change:;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
@stamblerre stamblerre modified the milestones: gopls/v0.5.0, gopls/v1.0.0 Jul 22, 2020
@stamblerre stamblerre assigned stamblerre and unassigned stamblerre Sep 10, 2020
Copy link

@gopherbot gopherbot commented Sep 13, 2020

Change mentions this issue: internal/lsp: pass options by reference instead of by value

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants