juliosueiras / terraform-lsp

Language Server Protocol for Terraform
MIT License
579 stars 37 forks source link

Segafault on GetVarAttributeCompletion #62

Open awilkins opened 4 years ago

awilkins commented 4 years ago

vscode + mauve.terraform 1.4.0 + tip of terraform-lsp as of b05a499

Seems to be when a matching config is not found when resolving locals.

Using reasonably complex locals with for x in setproduct(a, b, c) construct.

Have patched around by adding

# tfstructs/vars.go line 76  
if found == nil {
  return request.Result
}

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0xf5f2a9]

goroutine 75 [running]:
github.com/juliosueiras/terraform-lsp/tfstructs.GetVarAttributeCompletion(0xc0006372c0, 0x2, 0x2, 0x0, 0x0, 0x0, 0xc00048e380, 0x152cf20, 0xc0005fd3f0, 0xc0000400f7, ...)
    /home/awilkins/terraform-lsp/tfstructs/vars.go:76 +0x1319
github.com/juliosueiras/terraform-lsp/langserver.TextDocumentComplete(0x152c920, 0xc000457f50, 0xc0000400a0, 0x4e, 0x11, 0x24, 0x1, 0x0, 0x0, 0x0, ...)
    /home/awilkins/terraform-lsp/langserver/complete.go:324 +0x2996
reflect.Value.call(0x10b6580, 0x1291970, 0x13, 0x1241fad, 0x4, 0xc000457f80, 0x2, 0x2, 0x18, 0xc0004842c0, ...)
    /snap/go/5364/src/reflect/value.go:460 +0x5f6
reflect.Value.Call(0x10b6580, 0x1291970, 0x13, 0xc000457f80, 0x2, 0x2, 0x2, 0xc000457f80, 0x1)
    /snap/go/5364/src/reflect/value.go:321 +0xb4
github.com/creachadair/jrpc2/handler.newHandler.func7(0x152c920, 0xc000457f50, 0xc000182a80, 0x119d100, 0x42e84a, 0x10c3d40, 0x1d4c568)
    /home/awilkins/go/pkg/mod/github.com/creachadair/jrpc2@v0.1.2/handler/handler.go:222 +0x20a
github.com/creachadair/jrpc2/handler.Func.Handle(0xc0002e1480, 0x152c920, 0xc000457f50, 0xc000182a80, 0x0, 0x0, 0x152c920, 0xc000457f50)
    /home/awilkins/go/pkg/mod/github.com/creachadair/jrpc2@v0.1.2/handler/handler.go:23 +0x44
github.com/creachadair/jrpc2.(*Server).invoke(0xc0000ee300, 0x152c860, 0xc0005f60c0, 0x1510ae0, 0xc0002e1480, 0xc000182a80, 0x0, 0x0, 0x0, 0x0, ...)
    /home/awilkins/go/pkg/mod/github.com/creachadair/jrpc2@v0.1.2/server.go:294 +0x1ce
github.com/creachadair/jrpc2.(*Server).dispatch.func1(0xc00065c210, 0xc0000ee300, 0xc00060c510)
    /home/awilkins/go/pkg/mod/github.com/creachadair/jrpc2@v0.1.2/server.go:185 +0x125
created by github.com/creachadair/jrpc2.(*Server).dispatch
    /home/awilkins/go/pkg/mod/github.com/creachadair/jrpc2@v0.1.2/server.go:183 +0x13a
acdha commented 4 years ago

I ran into the same problem just now:

``` 2020-05-01T18:00:29.447-0400 [DEBUG] plugin: starting plugin: path=/Users/cadams/Projects/NLS/BARD/AWS-Infrastructure/.terraform/plugins/darwin_amd64/terraform-provider-aws_v2.60.0_x4 args=[/Users/cadams/Projects/NLS/BARD/AWS-Infrastructure/.terraform/plugins/darwin_amd64/terraform-provider-aws_v2.60.0_x4] 2020-05-01T18:00:29.465-0400 [DEBUG] plugin: plugin started: path=/Users/cadams/Projects/NLS/BARD/AWS-Infrastructure/.terraform/plugins/darwin_amd64/terraform-provider-aws_v2.60.0_x4 pid=28730 2020-05-01T18:00:29.465-0400 [DEBUG] plugin: waiting for RPC address: path=/Users/cadams/Projects/NLS/BARD/AWS-Infrastructure/.terraform/plugins/darwin_amd64/terraform-provider-aws_v2.60.0_x4 2020-05-01T18:00:29.507-0400 [INFO] plugin.terraform-provider-aws_v2.60.0_x4: configuring server automatic mTLS: timestamp=2020-05-01T18:00:29.506-0400 2020-05-01T18:00:29.552-0400 [DEBUG] plugin.terraform-provider-aws_v2.60.0_x4: plugin address: network=unix address=/var/folders/3s/23wfrdps69qfw6ly6d6039v80000gn/T/plugin629284809 timestamp=2020-05-01T18:00:29.552-0400 2020-05-01T18:00:29.552-0400 [DEBUG] plugin: using plugin: version=5 2020-05-01T18:00:29.710-0400 [DEBUG] plugin: plugin process exited: path=/Users/cadams/Projects/NLS/BARD/AWS-Infrastructure/.terraform/plugins/darwin_amd64/terraform-provider-aws_v2.60.0_x4 pid=28730 2020-05-01T18:00:29.711-0400 [DEBUG] plugin: plugin exited panic: interface conversion: hcl.Traverser is hcl.TraverseIndex, not hcl.TraverseAttr goroutine 31 [running]: github.com/juliosueiras/terraform-lsp/tfstructs.GetVarAttributeCompletion(0xc0009131a0, 0x2, 0x2, 0x0, 0x0, 0x0, 0xc0004c5300, 0x22282e0, 0xc00057bd90, 0xc0000392c7, ...) /go/src/github.com/juliosueiras/terraform-lsp/tfstructs/vars.go:189 +0x35f8 github.com/juliosueiras/terraform-lsp/langserver.TextDocumentComplete(0x2227ca0, 0xc000a80630, 0xc000039270, 0x44, 0xdf, 0x23, 0x2, 0x2a1622e, 0x1, 0x0, ...) /go/src/github.com/juliosueiras/terraform-lsp/langserver/complete.go:323 +0x18fb reflect.Value.call(0x1d82620, 0x1f71b28, 0x13, 0x1f205d1, 0x4, 0xc000a80810, 0x2, 0x2, 0x18, 0xc0005e29c0, ...) /usr/local/go/src/reflect/value.go:460 +0x5f6 reflect.Value.Call(0x1d82620, 0x1f71b28, 0x13, 0xc000a80810, 0x2, 0x2, 0x2, 0xc000a80810, 0x1) /usr/local/go/src/reflect/value.go:321 +0xb4 github.com/creachadair/jrpc2/handler.newHandler.func7(0x2227ca0, 0xc000a80630, 0xc000192100, 0x1e724e0, 0x102c50a, 0x1d922a0, 0x2ac0230) /go/src/github.com/juliosueiras/terraform-lsp/vendor/github.com/creachadair/jrpc2/handler/handler.go:222 +0x20a github.com/creachadair/jrpc2/handler.Func.Handle(0xc0002edbe0, 0x2227ca0, 0xc000a80630, 0xc000192100, 0x0, 0x0, 0x2227ca0, 0xc000a80630) /go/src/github.com/juliosueiras/terraform-lsp/vendor/github.com/creachadair/jrpc2/handler/handler.go:23 +0x44 github.com/creachadair/jrpc2.(*Server).invoke(0xc0000e2300, 0x2227be0, 0xc000192280, 0x2209ae0, 0xc0002edbe0, 0xc000192100, 0x0, 0x0, 0x0, 0x0, ...) /go/src/github.com/juliosueiras/terraform-lsp/vendor/github.com/creachadair/jrpc2/server.go:288 +0x177 github.com/creachadair/jrpc2.(*Server).dispatch.func1(0xc000bfa040, 0xc0000e2300, 0xc00027c000) /go/src/github.com/juliosueiras/terraform-lsp/vendor/github.com/creachadair/jrpc2/server.go:185 +0xae created by github.com/creachadair/jrpc2.(*Server).dispatch /go/src/github.com/juliosueiras/terraform-lsp/vendor/github.com/creachadair/jrpc2/server.go:183 +0x137 [Error - 6:00:29 PM] Connection to server got closed. Server will not be restarted. [Error - 6:00:29 PM] Request textDocument/completion failed. Error: Connection got disposed. at Object.dispose (/Users/cadams/.vscode/extensions/mauve.terraform-1.4.0/node_modules/vscode-jsonrpc/lib/main.js:876:25) at Object.dispose (/Users/cadams/.vscode/extensions/mauve.terraform-1.4.0/node_modules/vscode-languageclient/lib/client.js:71:35) at LanguageClient.handleConnectionClosed (/Users/cadams/.vscode/extensions/mauve.terraform-1.4.0/node_modules/vscode-languageclient/lib/client.js:2153:42) at LanguageClient.handleConnectionClosed (/Users/cadams/.vscode/extensions/mauve.terraform-1.4.0/node_modules/vscode-languageclient/lib/main.js:151:15) at closeHandler (/Users/cadams/.vscode/extensions/mauve.terraform-1.4.0/node_modules/vscode-languageclient/lib/client.js:2140:18) at CallbackList.invoke (/Users/cadams/.vscode/extensions/mauve.terraform-1.4.0/node_modules/vscode-jsonrpc/lib/events.js:62:39) at Emitter.fire (/Users/cadams/.vscode/extensions/mauve.terraform-1.4.0/node_modules/vscode-jsonrpc/lib/events.js:120:36) at closeHandler (/Users/cadams/.vscode/extensions/mauve.terraform-1.4.0/node_modules/vscode-jsonrpc/lib/main.js:226:26) at CallbackList.invoke (/Users/cadams/.vscode/extensions/mauve.terraform-1.4.0/node_modules/vscode-jsonrpc/lib/events.js:62:39) at Emitter.fire (/Users/cadams/.vscode/extensions/mauve.terraform-1.4.0/node_modules/vscode-jsonrpc/lib/events.js:120:36) at StreamMessageReader.fireClose (/Users/cadams/.vscode/extensions/mauve.terraform-1.4.0/node_modules/vscode-jsonrpc/lib/messageReader.js:111:27) at Socket. (/Users/cadams/.vscode/extensions/mauve.terraform-1.4.0/node_modules/vscode-jsonrpc/lib/messageReader.js:151:46) at Socket.emit (events.js:208:15) at Pipe. (net.js:588:12) ```

This seems to be most common when I'm refactoring things — as soon as I make half of a rename or restructure it crashes. Beyond handling that at all, I think there might be an argument for having an option to restart the language server manually or to wait before restarting after a failure — what happens now is that it crashes 5 times in a row within a second or two and then never restarts again.

juliosueiras commented 4 years ago

@acdha will take a look

awilkins commented 4 years ago

PR #74 should hopefully fix this.