DisposaBoy / GoSublime

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

GOSublime crashes if "too many errors" returned by 'go build'. #837

Closed david9991 closed 6 years ago

david9991 commented 6 years ago

GoSublime crashes if "too many errors" returned by 'go build'. e.g.

$ go build
...
syntax/syntax.go:121:29: too many errors
DisposaBoy commented 6 years ago

I need some instructions on to reproduce this.

david9991 commented 6 years ago

Log file: log.txt

david9991 commented 6 years ago

I just tried change some function declaration in my source, to produce enough errors. In this case, every time I try to compile this code, by cmd+. cmd + b, plugin host will crash.

david9991 commented 6 years ago

I cannot give you the full source code, but a patch I tried to produce errors. patch.txt

DisposaBoy commented 6 years ago

Maybe it's the same issue as https://github.com/DisposaBoy/GoSublime/issues/840

Have you tried disabling other plugins to isolate the issue to GoSublime?

You can also open the Sublime Text console ctrl+` IIRC, and run the go build command from there with import subprocess; subprocess.call(['go', 'build']). If that also crashes, it's almost certainly the same issue as #840 which appears to be a Sublime Text issue. To work around that you might have some luck if you downgrade Sublime Text, probably to a version less than 3170.

david9991 commented 6 years ago

Run import subprocess; subprocess.call(['go', 'build']) in console doesn't crash plugin host here, just returns 1.

screen shot 2018-06-12 at 8 41 08 am
david9991 commented 6 years ago

I found when crash occur, b.in.ReadBytes('\n') infunc (b *Broker) accept(jobsCh chan Job) (stopLooping bool) got EOF error. so stopLooping = true then the margo process exit. But I am not sure if this caused plugin_host crash.

DisposaBoy commented 6 years ago

Are you saying it doesn't crash if you replace that line with out=out,? that'd suggest that it's something to do with the content of the output.

Does the follow console command crash as well? from GoSublime.gosubl import gs; import subprocess; out = subprocess.Popen(['go', 'build'], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate(); print('output:', out); print('gs.ustr:', [gs.ustr(s) for s in out])

If it doesn't, does from GoSublime.gosubl import sh; sh.Command(['go', 'build']).run() or from GoSublime.gosubl import sh; sh.go(['build']) crash?

Can you also attach or email me (support@kuroku.io) the output? adding the following code on line 118 will write it to /tmp/output.log

    with open('/tmp/output.log', 'wb') as f:
        f.write(out)

Also what's the output of import locale; locale.getpreferredencoding()

DisposaBoy commented 6 years ago

margo exiting should be normal, it exits automatically if there are any issues reading or writing to the editor to avoid processes hanging around forever when you close the editor.

david9991 commented 6 years ago

I added some log in margo, here is the normal output:

2018/06/12 17:08:19 M [123 34 116 111 107 101 110 34 58 34 109 103 57 46 97 117 116 111 107 101 110 46 55 57 51 53 100 54 99 50 45 98 100 50 100 45 52 56 48 50 45 57 102 98 100 45 98 50 48 98 99 98 51 51 48 52 56 54 34 44 34 101 114 114 111 114 34 58 34 34 44 34 116 97 103 34 58 34 114 49 56 46 48 53 46 49 57 45 49 34 44 34 100 97 116 97 34 58 123 34 100 117 114 34 58 34 49 46 51 49 55 50 48 51 48 52 57 115 34 44 34 101 114 114 34 58 34 34 44 34 111 117 116 34 58 34 34 125 125] <nil>
2018/06/12 17:08:19 W {"token":"mg9.autoken.7935d6c2-bd2d-4802-9fbd-b20bcb330486","error":"","tag":"r18.05.19-1","data":{"dur":"1.317203049s","err":"","out":""}}
2018/06/12 17:08:19 CALL-done
2018/06/12 17:08:19 STOP false
2018/06/12 17:08:19 DEBUG2 {[]}
2018/06/12 17:08:19 M [123 34 116 111 107 101 110 34 58 34 109 103 57 46 97 117 116 111 107 101 110 46 100 52 52 99 55 55 102 53 45 57 50 55 50 45 52 101 54 57 45 98 98 55 48 45 98 52 48 55 49 57 50 101 100 53 49 53 34 44 34 101 114 114 111 114 34 58 34 34 44 34 116 97 103 34 58 34 114 49 56 46 48 53 46 49 57 45 49 34 44 34 100 97 116 97 34 58 123 34 67 97 110 100 105 100 97 116 101 115 34 58 91 93 125 125] <nil>
2018/06/12 17:08:19 W {"token":"mg9.autoken.d44c77f5-9272-4e69-bb70-b407192ed515","error":"","tag":"r18.05.19-1","data":{"Candidates":[]}}
2018/06/12 17:08:19 CALL-done
2018/06/12 17:08:20 STOP false
2018/06/12 17:08:20 DEBUG2 {[]}
2018/06/12 17:08:20 M [123 34 116 111 107 101 110 34 58 34 109 103 57 46 97 117 116 111 107 101 110 46 56 97 56 51 57 48 50 100 45 57 48 57 99 45 52 57 52 100 45 98 52 57 57 45 101 102 52 49 56 97 49 54 51 49 98 101 34 44 34 101 114 114 111 114 34 58 34 34 44 34 116 97 103 34 58 34 114 49 56 46 48 53 46 49 57 45 49 34 44 34 100 97 116 97 34 58 123 34 67 97 110 100 105 100 97 116 101 115 34 58 91 93 125 125] <nil>
2018/06/12 17:08:20 W {"token":"mg9.autoken.8a83902d-909c-494d-b499-ef418a1631be","error":"","tag":"r18.05.19-1","data":{"Candidates":[]}}
2018/06/12 17:08:20 CALL-done
2018/06/12 17:08:21 STOP false
2018/06/12 17:08:21 DEBUG2 {[]}
2018/06/12 17:08:21 M [123 34 116 111 107 101 110 34 58 34 109 103 57 46 97 117 116 111 107 101 110 46 101 101 97 98 102 53 56 101 45 101 51 101 97 45 52 55 55 49 45 57 57 57 101 45 97 100 100 57 53 50 101 54 50 54 54 51 34 44 34 101 114 114 111 114 34 58 34 34 44 34 116 97 103 34 58 34 114 49 56 46 48 53 46 49 57 45 49 34 44 34 100 97 116 97 34 58 123 34 67 97 110 100 105 100 97 116 101 115 34 58 91 93 125 125] <nil>
2018/06/12 17:08:21 W {"token":"mg9.autoken.eeabf58e-e3ea-4771-999e-add952e62663","error":"","tag":"r18.05.19-1","data":{"Candidates":[]}}
2018/06/12 17:08:21 CALL-done

and this is the log when it crash:

2018/06/12 17:23:43 DEBUG2 map[err:[35 32 112 111 99 111 103 114 97 112 104 46 99 111 109 47 112 108 99 99 47 115 121 110 116 97 120 10 115 121 110 116 97 120 47 115 121 110 116 97 120 46 103 111 58 50 55 58 49 48 58 32 117 110 100 101 102 105 110 101 100 58 32 83 121 110 116 97 120 69 114 114 111 114 10] dur:147.369307ms out:[]] exit status 2
2018/06/12 17:23:43 M [123 34 116 111 107 101 110 34 58 34 109 103 57 46 97 117 116 111 107 101 110 46 55 56 102 54 49 52 97 100 45 50 57 57 98 45 52 102 48 102 45 97 99 51 53 45 98 51 101 98 53 56 50 56 51 98 49 98 34 44 34 101 114 114 111 114 34 58 34 101 120 105 116 32 115 116 97 116 117 115 32 50 34 44 34 116 97 103 34 58 34 114 49 56 46 48 53 46 49 57 45 49 34 44 34 100 97 116 97 34 58 123 34 100 117 114 34 58 34 49 52 55 46 51 54 57 51 48 55 109 115 34 44 34 101 114 114 34 58 34 98 97 115 101 54 52 58 73 121 66 119 98 50 78 118 90 51 74 104 99 71 103 117 89 50 57 116 76 51 66 115 89 50 77 118 99 51 108 117 100 71 70 52 67 110 78 53 98 110 82 104 101 67 57 122 101 87 53 48 89 88 103 117 90 50 56 54 77 106 99 54 77 84 65 54 73 72 86 117 90 71 86 109 97 87 53 108 90 68 111 103 85 51 108 117 100 71 70 52 82 88 74 121 98 51 73 75 34 44 34 111 117 116 34 58 34 34 125 125] <nil>
2018/06/12 17:23:43 W {"token":"mg9.autoken.78f614ad-299b-4f0f-ac35-b3eb58283b1b","error":"exit status 2","tag":"r18.05.19-1","data":{"dur":"147.369307ms","err":"base64:IyBwb2NvZ3JhcGguY29tL3BsY2Mvc3ludGF4CnN5bnRheC9zeW50YXguZ286Mjc6MTA6IHVuZGVmaW5lZDogU3ludGF4RXJyb3IK","out":""}}
2018/06/12 17:23:43 CALL-done
2018/06/12 17:23:43 IO EOF
2018/06/12 17:23:43 STOP true
2018/06/12 17:23:43 Loop exited
2018/06/12 17:23:43 Exited!!!!!!!
2018/06/12 17:23:43 Exited!!!!!!!
2018/06/12 17:23:43 Exited!!!!!!!
2018/06/12 17:23:43 M [123 34 116 111 107 101 110 34 58 34 109 97 114 103 111 46 98 121 101 45 110 105 34 44 34 101 114 114 111 114 34 58 34 34 44 34 116 97 103 34 58 34 114 49 56 46 48 53 46 49 57 45 49 34 44 34 100 97 116 97 34 58 123 34 115 101 114 118 101 100 34 58 55 53 50 44 34 117 112 116 105 109 101 34 58 34 49 55 109 50 55 46 51 54 51 55 53 50 57 56 49 115 34 125 125] <nil>

So in the normal log, we cannot see the loop exit.

david9991 commented 6 years ago

And I tried to produce few error, without plugin crash:

2018/06/12 17:26:19 W {"token":"mg9.autoken.1334421f-1560-4030-9948-0b2da709d028","error":"","tag":"r18.05.19-1","data":{"Candidates":[]}}
2018/06/12 17:26:19 CALL-done
2018/06/12 17:26:19 Run end
2018/06/12 17:26:19 ERROR # pocograph.com/plcc
./plcc.go:34:34: syntax error: unexpected newline, expecting comma or )
./plcc.go:46:2: syntax error: unexpected case, expecting }
./plcc.go:48:3: syntax error: non-declaration statement outside function body
...
2018/06/12 17:26:19 CALL-done
2018/06/12 17:26:20 STOP false
2018/06/12 17:26:20 DEBUG2 {[]}

I keep getting stopLooping = false.

david9991 commented 6 years ago

With some investigation, I can provide more information, but still cannot locate cause of crash:

  1. err := c.Run() in func (m *mSh) Call() (interface{}, string) cause the I/O EOF in some condition maybe.
  2. After crash, def _read_stdout(proc) in mg9.py cannot receive any output due to plugin host already crashed.
  3. After err := c.Run() run in margo, I got Child exit or Broken pipe signal randomly.
  4. c.Run() returns exit status 2 when it crash.
  5. I have tried exec.CommandContext() with exec.Start(), it won't crash.
  6. I have tried exec.Command() with exec.Start(), it will crash.
  7. I have tried exec.Command() with exec.Start() and exec.Wait() it will crash.
  8. I have tried to put exec.Run() in a groutine, it will crash.
  9. I have tried force to use the Response Message which sent when it crash, instead of the normal compiled message, it won't crash, so the crash may not caused by the Response Message.
  10. I cannot explain why a c.Run() could cause os.Stdin of parent process gets I/O EOF error. I will keep investigating on it, some more advice?
  11. I tried upgrade the golang from 1.9.2 to 1.10.3, with no luck.
david9991 commented 6 years ago

both

from GoSublime.gosubl import gs; import subprocess; out = subprocess.Popen(['go', 'build'], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate(); print('output:', out); print('gs.ustr:', [gs.ustr(s) for s in out])

and

If it doesn't, does from GoSublime.gosubl import sh; sh.Command(['go', 'build']).run() or from GoSublime.gosubl import sh; sh.go(['build'])

doesn't crash.

david9991 commented 6 years ago

Output of import locale; locale.getpreferredencoding()

>>> import locale; locale.getpreferredencoding()
'US-ASCII'
DisposaBoy commented 6 years ago

To be clear: if plugin_host crashes or you close Sublime Text, margo will exit automatically so the EOF might not mean anything depending on where and when you're seeing it.

Also, have you tried the development branch. It has a new implementation of margo that might work better if it happens to be a margo issue and not just another case of the Sublime Text bug.

david9991 commented 6 years ago

Sorry about have no enough time to follow this issue. I have tried your development branch, with no luck... and I'll try to continue debug this if have enough time.

DisposaBoy commented 6 years ago

(I'm too lazy to read through all the comments)... make sure to try downgrading Sublime Text as the current and some previous versions have a bug where certain signals in child processes will cause plugin_host to crash. You can just change the version number in the download url e.g. for version 3143 use https://download.sublimetext.com/Sublime%20Text%20Build%203143.dmg