DisposaBoy / GoSublime

A Golang plugin collection for SublimeText 3, providing code completion and other IDE-like features.
MIT License
3.42k stars 298 forks source link

Crashes all Sublime plugins when a test dereferences a nil pointer #840

Closed jonstaryuk closed 6 years ago

jonstaryuk commented 6 years ago

I'm using macOS 10.13.4, Sublime Text build 3175, GoSublime v18.05.19.

Steps to reproduce:

  1. Create a file named foo_test.go
package test

import "testing"

type fooer interface {
    foo()
}

func TestFoo(t *testing.T) {
    var f fooer
    f.foo()
}
  1. Open 9o and run go test

  2. Sublime's plugin host crashes. All plugins are unavailable until you restart the app.

screen shot 2018-05-26 at 12 11 00 am

Other types of panics, such as calling panic() in the test, seem to be handled normally and do not result in a crash.

DisposaBoy commented 6 years ago

I can't reproduce this on Linux (I don't have access to a Mac right now) with ST 3176.

jonstaryuk commented 6 years ago

It happens with any of these:

In general, it seems like it crashes whenever the test binary receives an error signal (such as SIGSEGV) but not when the panic comes from the Go runtime (such as index out of range). However, this test doesn't cause a plugin crash, even though it kills the test binary:

p, err := os.FindProcess(os.Getpid())
if err != nil {
    t.Fatal(err)
}
p.Signal(syscall.SIGSEGV)

So it only happens when the Go runtime catches the segfault in order to write its panic error message.

DisposaBoy commented 6 years ago

My guess is that maybe some signal (e.g. SIGPIPE) is reaching the parent, but I'm not sure how to reproduce that.

jonstaryuk commented 6 years ago

Before:

screen shot 2018-05-26 at 11 14 09 am

After:

screen shot 2018-05-26 at 11 14 31 am

DisposaBoy commented 6 years ago

@ inancgumus

The exception on sh.py:121 suggests Popen.communicate() returns None? add a print(err) above it to see what it actually returns.

That it works when sh isn't loaded might point to issues when shell commands are run. Open the ST console and run from GoSublime.gosubl import sh; sh.ShellCommand('go version').run() to see if it succeeds. It should output the Result object with no exceptions.

DisposaBoy commented 6 years ago

@jonstaryuk I see acall gocode_calltip and acall play in the output. Are you sure you're using the development branch with the new version of margo enabled? at least the acall play shouldn't be there.

DisposaBoy commented 6 years ago

Also make sure there isn't multiple copies of GS installed, I've seen Package Control do that in the past.

jonstaryuk commented 6 years ago

I removed the package control version and I've been using a git clone of this repo. I just cleaned it out again — verified that GS was completely uninstalled, cloned into Packages/GoSublime, checked out development (commit ce0aebc) — and when I start Sublime Text this stuff is still there:

reloading plugin TerminalView.sublime_view_cache
reloading plugin TerminalView.TerminalView
reloading plugin TerminalView.utils
reloading plugin Wrap Plus.wrap_plus
reloading plugin Anaconda.anaconda
reloading plugin Anaconda.setup
reloading plugin Anaconda.version
reloading plugin ColorPicker.sublimecp
reloading plugin EasyClangComplete.EasyClangComplete
reloading plugin GoSublime.GoSublime
reloading plugin GoSublime.gs9o
reloading plugin GoSublime.gscommands
reloading plugin GoSublime.gscomplete
reloading plugin GoSublime.gsdoc
reloading plugin GoSublime.gsev
reloading plugin GoSublime.gslint
reloading plugin GoSublime.gspalette
reloading plugin GoSublime.gstest
reloading plugin GoSublime.margo_sublime
reloading plugin Pretty JSON.PrettyJson
reloading plugin Pretty JSON.PrettyJsonListeners
reloading plugin Pretty YAML.PrettyYaml
reloading plugin Sublime Tutor.sublime_tutor
reloading plugin TypeScript.main
2018-05-26 15:15:40,281: 140735718552448: WARNING: TypeScript plugin initialized.
reloading plugin VUEFormatter.VUEFormatter
plugins loaded
LSP: global clients: jsts=True, clangd=False, vue-ls=True
lang_service_enabled: True
Path of tsserver.js: /Users/jon/Library/Application Support/Sublime Text 3/Packages/TypeScript/tsserver/tsserver.js
Path of tsc.js: /Users/jon/Library/Application Support/Sublime Text 3/Packages/TypeScript/tsserver/tsc.js
Trying to spawn node executable from: /usr/local/bin/node
ref view not found
GoSublime r18.04.30-1: gs.init()
GoSublime r18.04.30-1: sh.init()
GoSublime r18.04.30-1 sh: using shell env GOPATH=/Users/jon/go
GoSublime r18.04.30-1 sh: using shell env GOROOT=/usr/local/Cellar/go/1.10.2/libexec
GoSublime r18.04.30-1 sh: using shell env PATH=/usr/local/opt/llvm/bin:/Users/jon/Library/Application Support/Sublime Text 3/Packages/GoSublime/bin:/Users/jon/Library/Application Support/Sublime Text 3/Packages/User/GoSublime/bin:/Users/jon/go/bin:/Users/jon/Applications/google-cloud-sdk/bin:/Users/jon/bin:/usr/local/go/bin:/usr/local/opt/go/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/MacGPG2/bin:/Applications/Wireshark.app/Contents/MacOS:/Users/jon/go/bin
GoSublime r18.04.30-1 sh: go version: `go1.10.2` (raw version string `go1.10.2`)
GoSublime r18.04.30-1 sh: shell bootstrap took 0.960s
GoSublime r18.04.30-1: margo.init()
[15:15:41] margo: agent#007: startingGoSublime r18.04.30-1: mg9.init()

** 2018-05-26 15:15:41.405526 **:
GoSublime init r18.04.30-1 (0.001s)
|   install margo: no
|   install state: done
| sublime.version: 3175
| sublime.channel: dev
|       about.ann: a18.04.30-1
|   about.version: r18.04.30-1
|         version: r18.04.30-1
|        platform: osx-x64
|            ~bin: ~/Library/Application Support/Sublime Text 3/Packages/User/GoSublime/osx-x64/bin
|       margo.exe: ~bin/gosublime.margo_r18.04.30-1_go1.10.2.exe (ok)
|          go.exe: /usr/local/Cellar/go/1.10.2/libexec/bin/go (ok)
|      go.version: go1.10.2
|          GOROOT: /usr/local/Cellar/go/1.10.2/libexec
|          GOPATH: ~/go
|           GOBIN: (not set)
|       set.shell: []
|       env.shell: /usr/local/bin/fish
|       shell.cmd: ['/usr/local/bin/fish', '-l', '-c', '${CMD}']
|    sh.bootstrap: 
|                >  using shell env GOPATH=~/go
|                >  using shell env GOROOT=/usr/local/Cellar/go/1.10.2/libexec
|                >  using shell env PATH=/usr/local/opt/llvm/bin:~/Library/Application Support/Sublime Text 3/Packages/GoSublime/bin:~/Library/Application Support/Sublime Text 3/Packages/User/GoSublime/bin:~/go/bin:~/Applications/google-cloud-sdk/bin:~/bin:/usr/local/go/bin:/usr/local/opt/go/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/MacGPG2/bin:/Applications/Wireshark.app/Contents/MacOS:~/go/bin
|                >  go version: `go1.10.2` (raw version string `go1.10.2`)
|                >  shell bootstrap took 0.960s
|                >
--------------------------------

Package Control: Skipping automatic upgrade, last run at 2018-05-26 15:14:00, next run at 2018-05-26 16:14:00 or after
[15:15:43] margo: agent#007: ['/Users/jon/Library/Application Support/Sublime Text 3/Packages/GoSublime/bin/margo.sh', 'start', 'margo.sublime', '-codec', 'msgpack']
[15:15:43] margo: agent#007: log: ``` go install -v -tags="margo margo_extension" -i margo.sh/cmd/margo.sublime ```
[15:15:44] margo: agent#007: log: ``` "/Users/jon/Library/Application Support/Sublime Text 3/Packages/GoSublime/bin/margo.sublime" -codec msgpack ```
[15:15:44] margo: agent#007: log: store.go:137: started
acall gocode_calltip
acall lint
acall gocode_calltip
acall gocode_calltip
acall gocode_calltip
acall gocode_calltip

(etc...)
jonstaryuk commented 6 years ago

Also I just found this in Packages/User/GoSublime/osx-x64/log.txt:


** 2018-05-26 11:35:16.230055 **:
agent#007: GoSublime: Traceback (most recent call last):
  File "/Users/jon/Library/Application Support/Sublime Text 3/Packages/GoSublime/gosubl/margo_agent.py", line 274, in _handle_recv
    self._handle_recv_ipc(v)
  File "/Users/jon/Library/Application Support/Sublime Text 3/Packages/GoSublime/gosubl/margo_agent.py", line 259, in _handle_recv_ipc
    self._notify_ready()
  File "/Users/jon/Library/Application Support/Sublime Text 3/Packages/GoSublime/gosubl/margo_agent.py", line 256, in _notify_ready
    self.mg.agent_ready(self)
  File "/Users/jon/Library/Application Support/Sublime Text 3/Packages/GoSublime/gosubl/margo.py", line 154, in agent_ready
    self.on_activated(gs.active_view())
  File "/Users/jon/Library/Application Support/Sublime Text 3/Packages/GoSublime/gosubl/margo.py", line 190, in on_activated
    self.queue(view=view, actions=[actions.ViewActivated])
  File "/Users/jon/Library/Application Support/Sublime Text 3/Packages/GoSublime/gosubl/margo.py", line 169, in queue
    self.agent.queue(actions=actions, view=view)
  File "/Users/jon/Library/Application Support/Sublime Text 3/Packages/GoSublime/gosubl/margo_agent.py", line 194, in queue
    p = (act, view.id())
AttributeError: 'NoneType' object has no attribute 'id'
--------------------------------
DisposaBoy commented 6 years ago

@jonstaryuk Using your code as a package main command instead of a test, I was able to reproduce this on ST using Python 3.3.6 by using subprocess.call() so I don't think it's a GS issue. It doesn't happen on ST with Python 3.3.4 or 3.3.3 (I forget) so I'm guessing something changed during one of those versions. I'll continue investigating when I have some time.

DisposaBoy commented 6 years ago

Just an update:

This seems to be a known issue https://github.com/SublimeTextIssues/Core/issues/2327

I'd still like to work around it if possible, but I have no ideas about how to do that yet.

Edit: maybe try downgrading Sublime Text.

anacrolix commented 6 years ago

I get this crash with ST build 3170 (and 3176).

DisposaBoy commented 6 years ago

Since Sublime HQ doesn't seem to be doing anything about it, the only thing I can suggest now is to try an earlier build or help me find some way to reproduce it on Linux. I think a possible work-around is to stop using stdout, but I no longer have access to a Mac (assuming this is the only OS it happens on) so have no way to test the theory and it will take some time to change the IPC anyway.

DisposaBoy commented 6 years ago

In-case people are still landing on this issue but aren't in the loop:

From comments in https://github.com/SublimeTextIssues/Core/issues/2327 it seems the last non-crashing version of Sublime Text is 3161. To download an older version, you can simply change the version number in the download URL e.g. https://download.sublimetext.com/Sublime%20Text%20Build%203161.dmg

anacrolix commented 6 years ago

Has something changed? What's the recommended course of action now?

DisposaBoy commented 6 years ago

@anacrolix Apparently they have a fix for it https://github.com/SublimeTextIssues/Core/issues/2327#issuecomment-425767504

kylebebak commented 6 years ago

I can confirm that I no longer experience this issue on OSX, ST build 3180.