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: nil pointer dereference when editing a file from a cousin directory #41777
Comments
Thank you for the detailed report! /cc @pjweinb, who also saw this and was looking into fixing it |
@kortschak Sure. With your changes I get the same result as when I tried my fix. I get this stack trace:
It looks like @@ -235,6 +236,7 @@ func (s *Server) didModifyFiles(ctx context.Context, modifications []source.File
if mod.OnDisk || mod.Action != source.Change {
continue
}
+ _ = s.wasFirstChange(mod.URI)
snapshot, ok := snapshotByURI[mod.URI]
if !ok {
continue but I haven't read the code enough to understand what the proper fix might be. |
Yes, that's what I've come to as well. That is #41779. |
Change https://golang.org/cl/259457 mentions this issue: |
Change https://golang.org/cl/259621 mentions this issue: |
Change https://golang.org/cl/259877 mentions this issue: |
What did you do?
I am editing code in a GOPATH project.
$GOPATH/src/p
is the root of a large Go source tree (all of our internal code at my company).I can't make the crash happen with a small GOPATH; I suspect it requires a large amount of code to enlarge a race window or something like that. But I did minimize the repro a little:
The directory
a
is empty.The file
scratch/x.go
contains a little bit of code (doesn't much matter what):I am using gopls via govim. My working directory is
$GOPATH/src/p/a
and I edit x.go:and immediately start making edits to the file (say, moving my cursor to the end of one of the lines and holding down backspace).
What did you expect to see?
No crashes
What did you see instead?
Govim freezes because gopls has crashed. Here is a stack trace:
If I edit the file from the project root (
$GOPATH/src/p
) or from insidescratch
, the crash doesn't seem to happen. Being inside another directory and editing the file as../scratch/x.go
seems to matter.I poked around in the code a little and I see that the map in question is indeed populated with nil snapshots a few lines earlier here so that when we get down to here we call
source.IsGenerated
withsnapshot == nil
.I tried making the trivial change of not filling
snapshotByURI
with nils but that broke something else. I stared at the code for a while but it's hard for me to tell what the intent was.It also seems like there's an unreachable condition immediately before the crash line here.
I'm guessing that for someone familiar with the code, the bug and fix will be obvious.
Build info
(I updated to latest to confirm the bug but I saw this with a variety of older gopls versions as well.)
cc:
The text was updated successfully, but these errors were encountered: