Skip to content

x/tools/gopls: crash trying to add an import manually with gopls built using go1.14beta1 #36610

Closed
@psanford

Description

@psanford

What version of Go are you using (go version)?

$ go version
go1.14beta1

Does this issue reproduce with the latest release?

I reproduced this on a gopls build from master.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/psanford/.cache/go-build"
GOENV="/home/psanford/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/tmp/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/psanford/lib/.go-1.14beta1-ebe68aa4219b673dbd060b8a6d9a339b6b6b0383772aa4349c8183f0a8f339e4"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/psanford/lib/.go-1.14beta1-ebe68aa4219b673dbd060b8a6d9a339b6b6b0383772aa4349c8183f0a8f339e4/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/psanford/projects/thirdparty/gotools/gopls/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build660370694=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I tried to manually add an import to the import block of the following code (above the "fmt"):

package main

import (
	"fmt"
)

func main() {
	fmt.Println("hello world")
}

After inserting a single non-quote character gopls crashed:

package main

import (
	m
	"fmt"
)

func main() {
	fmt.Println("hello world")
}

The stack trace from gopls:

panic: runtime error: slice bounds out of range [14:0]

goroutine 1797 [running]:
golang.org/x/tools/internal/lsp/source.trimToImports(0xc0002d4540, 0xc0003f7f00, 0xc000226900, 0x50, 0xb7, 0xda4900, 0xc00242ed40, 0x0, 0x0)
	/home/psanford/projects/thirdparty/gotools/internal/lsp/source/format.go:253 +0x505
golang.org/x/tools/internal/lsp/source.computeOneImportFixEdits(0xdb40a0, 0xc00090ce10, 0xdc1a00, 0xc0003c0240, 0xdb42a0, 0xc00242eae0, 0xc002ce85d8, 0xc0022dad00, 0xc002ce8548, 0x45140e, ...)
	/home/psanford/projects/thirdparty/gotools/internal/lsp/source/format.go:151 +0x1cc
golang.org/x/tools/internal/lsp/source.(*completer).importEdits(0xc0020f9a40, 0xc0021d3bf0, 0xc002ce8830, 0x1, 0x1, 0xc0016e17c0, 0xb)
	/home/psanford/projects/thirdparty/gotools/internal/lsp/source/completion_format.go:225 +0x284
golang.org/x/tools/internal/lsp/source.(*completer).item(0xc0020f9a40, 0xdc3be0, 0xc00053cfc0, 0x3fb1eb851eb851ec, 0xc645ff, 0x3, 0x0, 0xc0021d3bf0, 0x0, 0x0, ...)
	/home/psanford/projects/thirdparty/gotools/internal/lsp/source/completion_format.go:119 +0xf93
golang.org/x/tools/internal/lsp/source.(*completer).found(0xc0020f9a40, 0xdc3be0, 0xc00053cfc0, 0x3fb1eb851eb851ec, 0xc645ff, 0x3, 0x0, 0xc0021d3bf0)
	/home/psanford/projects/thirdparty/gotools/internal/lsp/source/completion.go:351 +0x2bc
golang.org/x/tools/internal/lsp/source.(*completer).lexical.func1(0xc645f9, 0x9, 0x0, 0x0, 0xc645ff, 0x3, 0x0, 0x7)
	/home/psanford/projects/thirdparty/gotools/internal/lsp/source/completion.go:903 +0x2ef
golang.org/x/tools/internal/imports.getAllCandidates.func3(0xc002072580, 0xc002072580)
	/home/psanford/projects/thirdparty/gotools/internal/imports/fix.go:688 +0x120
golang.org/x/tools/internal/imports.getCandidatePkgs(0xdb4060, 0xc00053cde0, 0xc002545520, 0xc002560187, 0x28, 0xc001a50b4c, 0x4, 0xc002754460, 0x203000, 0xc0001b7b80)
	/home/psanford/projects/thirdparty/gotools/internal/imports/fix.go:607 +0x30c
golang.org/x/tools/internal/imports.getAllCandidates(0xdb4060, 0xc00053cde0, 0xc0021d3b00, 0x126c365, 0x1, 0xc002560187, 0x28, 0xc001a50b4c, 0x4, 0xc002754460, ...)
	/home/psanford/projects/thirdparty/gotools/internal/imports/fix.go:700 +0x16b
golang.org/x/tools/internal/imports.GetAllCandidates(0xdb4060, 0xc00053cde0, 0xc0021d3b00, 0x126c365, 0x1, 0xc002560187, 0x28, 0xc001a50b4c, 0x4, 0xc002545500, ...)
	/home/psanford/projects/thirdparty/gotools/internal/imports/imports.go:126 +0x106
golang.org/x/tools/internal/lsp/source.(*completer).lexical.func2(0xc002545500, 0xc002545500, 0xc00053cde0)
	/home/psanford/projects/thirdparty/gotools/internal/lsp/source/completion.go:925 +0xf4
golang.org/x/tools/internal/lsp/cache.(*view).RunProcessEnvFunc(0xc0003c0240, 0xdb4060, 0xc00053cde0, 0xc002072080, 0x0, 0x0)
	/home/psanford/projects/thirdparty/gotools/internal/lsp/cache/view.go:307 +0xf3
golang.org/x/tools/internal/lsp/source.(*completer).lexical(0xc0020f9a40, 0x0, 0x0)
	/home/psanford/projects/thirdparty/gotools/internal/lsp/source/completion.go:924 +0xc70
golang.org/x/tools/internal/lsp/source.Completion(0xdb40a0, 0xc00090ce10, 0xdc0d00, 0xc000690500, 0xdb27a0, 0xc0015fa600, 0x4008000000000000, 0x4000000000000000, 0x0, 0x0, ...)
	/home/psanford/projects/thirdparty/gotools/internal/lsp/source/completion.go:530 +0xcad
golang.org/x/tools/internal/lsp.(*Server).completion(0xc00028fce0, 0xdb40a0, 0xc00205e690, 0xc000519920, 0x0, 0x0, 0xc001252fd0)
	/home/psanford/projects/thirdparty/gotools/internal/lsp/completion.go:35 +0x7be
golang.org/x/tools/internal/lsp.(*Server).Completion(0xc00028fce0, 0xdb40a0, 0xc00205e690, 0xc000519920, 0xc000519920, 0x0, 0x0)
	/home/psanford/projects/thirdparty/gotools/internal/lsp/server.go:179 +0x49
golang.org/x/tools/internal/lsp/protocol.serverHandler.Deliver(0xdca9a0, 0xc00028fce0, 0xdb40a0, 0xc00205e690, 0xc0022e4780, 0xc00205e600, 0xc0025aefa0)
	/home/psanford/projects/thirdparty/gotools/internal/lsp/protocol/tsserver.go:316 +0x2596
golang.org/x/tools/internal/jsonrpc2.(*Conn).Run.func1(0xc001cfafc0, 0xc0022e4780, 0xc0002cd9e0, 0xdb40a0, 0xc00205e690, 0x0, 0x0, 0xc001ebd140)
	/home/psanford/projects/thirdparty/gotools/internal/jsonrpc2/jsonrpc2.go:370 +0x160
created by golang.org/x/tools/internal/jsonrpc2.(*Conn).Run
	/home/psanford/projects/thirdparty/gotools/internal/jsonrpc2/jsonrpc2.go:354 +0x874

Process gopls stderr<1> finished

I think this started happening after switching to go1.14.beta1 and rebuilding gopls.

cc: @heschik

Activity

added this to the Unreleased milestone on Jan 16, 2020
added
ToolsThis label describes issues relating to any tools in the x/tools repository.
goplsIssues related to the Go language server, gopls.
on Jan 16, 2020
gopherbot

gopherbot commented on Jan 16, 2020

@gopherbot
Contributor

Thank you for filing a gopls issue! Please take a look at the Troubleshooting guide, and make sure that you have provided all of the relevant information here.

gopherbot

gopherbot commented on Jan 17, 2020

@gopherbot
Contributor

Change https://golang.org/cl/215119 mentions this issue: internal/lsp/source: trim file very carefully

changed the title [-]x/tools/gopls: Crash trying to add an import manually with gopls built using go1.14beta1[/-] [+]x/tools/gopls: crash trying to add an import manually with gopls built using go1.14beta1[/+] on Jan 17, 2020
locked and limited conversation to collaborators on Jan 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @psanford@stamblerre@gopherbot

        Issue actions

          x/tools/gopls: crash trying to add an import manually with gopls built using go1.14beta1 · Issue #36610 · golang/go