Crash when removing a folder from sublime
gerardroche opened this issue · comments
LSP crashes sublime, and also various other programs like Firefox, kitty terminal, etc. This usually occurs when removing a folder from sublime.
To Reproduce
I can't always reproduce it, I think it happens when you remove several folders in quick succession. I use my Sesame plugin to add and remove folders. It essentially runs this code to remove a folder, pretty normal code:
def _remove_folder(window: Window, folder: str) -> None:
window.run_command('remove_folder', {
'dirs': [folder]
})
https://github.com/gerardroche/sublime-sesame/blob/master/plugin.py#L304
Here is the plugin_host-3.3-on_exit.log
:
Traceback (most recent call last):
File "/home/code/path/to/sublime-text/Packages/LSP/plugin/core/transports.py", line 191, in invoke
callback_object.on_transport_close(exit_code, exception)
File "/home/code/path/to/sublime-text/Packages/LSP/plugin/core/sessions.py", line 2171, in on_transport_close
mgr.on_post_exit_async(self, exit_code, exception)
File "/home/code/path/to/sublime-text/Packages/LSP/plugin/core/windows.py", line 382, in on_post_exit_async
listener.on_session_shutdown_async(session)
File "/home/code/path/to/sublime-text/Packages/LSP/plugin/documents.py", line 242, in on_session_shutdown_async
removed_session.on_before_remove()
File "/home/code/path/to/sublime-text/Packages/LSP/plugin/session_view.py", line 97, in on_before_remove
self._code_lenses.clear_view()
File "/home/code/path/to/sublime-text/Packages/LSP/plugin/code_lens.py", line 130, in clear_view
self._phantom.update([])
File "/home/code/path/to/sublime_text_4/Lib/python33/sublime.py", line 1926, in update
for phantom, region in zip(self.phantoms, regions):
TypeError: zip argument #2 must support iteration
Traceback (most recent call last):
File "/home/code/path/to/sublime-text/Packages/LSP/plugin/core/transports.py", line 191, in invoke
callback_object.on_transport_close(exit_code, exception)
File "/home/code/path/to/sublime-text/Packages/LSP/plugin/core/sessions.py", line 2171, in on_transport_close
mgr.on_post_exit_async(self, exit_code, exception)
File "/home/code/path/to/sublime-text/Packages/LSP/plugin/core/windows.py", line 382, in on_post_exit_async
listener.on_session_shutdown_async(session)
File "/home/code/path/to/sublime-text/Packages/LSP/plugin/documents.py", line 242, in on_session_shutdown_async
removed_session.on_before_remove()
File "/home/code/path/to/sublime-text/Packages/LSP/plugin/session_view.py", line 97, in on_before_remove
self._code_lenses.clear_view()
File "/home/code/path/to/sublime-text/Packages/LSP/plugin/code_lens.py", line 130, in clear_view
self._phantom.update([])
File "/home/code/path/to/sublime_text_4/Lib/python33/sublime.py", line 1926, in update
for phantom, region in zip(self.phantoms, regions):
TypeError: zip argument #2 must support iteration
Traceback (most recent call last):
File "/home/code/path/to/sublime-text/Packages/LSP/plugin/core/transports.py", line 191, in invoke
callback_object.on_transport_close(exit_code, exception)
File "/home/code/path/to/sublime-text/Packages/LSP/plugin/core/sessions.py", line 2171, in on_transport_close
mgr.on_post_exit_async(self, exit_code, exception)
File "/home/code/path/to/sublime-text/Packages/LSP/plugin/core/windows.py", line 382, in on_post_exit_async
listener.on_session_shutdown_async(session)
File "/home/code/path/to/sublime-text/Packages/LSP/plugin/documents.py", line 242, in on_session_shutdown_async
Environment (please complete the following information):
- OS: Ubuntu
- Sublime Text version: 4168
- LSP version: latest
- Language servers used:Volar, phpactor, Tailwindcss, eslint
Server crashing should not cause a crash of unrelated processes or even ST (only the plugin process). Unless it's a matter of server using all available RAM and affecting other apps that way.
The log I posted above doesn't have anything to do with this issue. I narrowed it down to the phpactor language-server. But yes, it's strange it crashes other programs. It's not a memory issue. I have 32G and I checked it and can reliably reproduce it now. It's probably not the plugin itself, but the language-server or php or sublime or all the above.
It happens when you remove two folders quickly. About less than 1sec apart. I use my Sesame plugin so it's easy to remove folders quickly.
In my lsp config I have the client:
"clients": {
"phpactor": {
"command": [
"php",
"-d",
"xdebug.mode=off",
"/usr/local/bin/phpactor",
"language-server",
],
"enabled": true,
"languageId": "php",
"scopes": [
"source.php",
"embedding.php"
],
"syntaxes": [
"Packages/PHP/PHP.sublime-syntax"
],
"disabled_capabilities": {
},
},
},
To reproduce,
- add three project folders to sublime
- open a php file (opening a php file initialises the language-server).
- remove two of the folders one after the other quickly (less than about 1 sec apart)
I enabled phpactor logging but there is nothing of note in the log.
Sublime doesn't seem to generate any exit log or crash report either.
Doesn't seem to reproduce on mac. I've made a video so that you can verify if I did test the way you explained:
Screen.Recording.2024-01-23.at.20.42.37.mov
Maybe try to make some changes in vendor/amphp/process/lib/Internal/Posix/Runner.php
. That file has potentially dangerous functions for killing processes. Maybe something goes wrong there on Linux. You could intentionally break this code to see if that changes anything.
(disclaimer: I have no idea if that code is even used)
That posix runner looks insane. That code scares me.
I think it's this:
https://github.com/amphp/process/blob/v1.1.4/lib/Internal/Posix/Runner.php#L197
@\posix_kill($pid, 9);
When there is an error, $pid
is null and this causes everything to crash. When add a null check, the problem seems to go away.
The php docs says nothing about null, but I think a null would be coerced to 0 so posix_kill()
would receive 0 in the case of an error.
php > var_dump((int) null);
int(0)
phpactor is using an old version of amphp/process: v1.1.4 - the newest version is v2.0.1 so maybe it's fixed. The newer code looks a lot better.
Thanks again @rchl
Closing as it's a phpactor issue: phpactor/phpactor#2516