python-language-server icon indicating copy to clipboard operation
python-language-server copied to clipboard

LS won't close

Open CMLL opened this issue 5 years ago • 19 comments

Environment data

  • Language Server version: 0.4.96
  • OS and version: Ubuntu 19.04
  • Python version (& distribution if applicable, e.g. Anaconda): 2.7.15

Expected behaviour

Language server closes when the vscode exits.

Actual behaviour

Process remains open in the background.

I left vscode open overnight at work with a project open, when I got in this morning the PC was pretty slow, so I ran a htop and noticed that the VIRT memory of the LS process was about 80GB. I closed down the VSCode window to clear the process, but even after closing vscode the LS continued open. Waited a couple of minutes and then killed it in order to start a new one.

Not sure if this should be treated as 2 different issues, the high VIRT memory and the LS not closing down.

Code Snippet / Additional lnformation

image

CMLL avatar Nov 06 '19 15:11 CMLL

LS monitors parent process and normally closes down even if VSC didn't send the shutdown request. So I guess it may be stuck somewhere waiting and does not get time ticks?

MikhailArkhipov avatar Nov 06 '19 17:11 MikhailArkhipov

I wouldn't worry about the high virtual count. I've seen things like Chrome's NaCl runtime do the same thing. Since we're in .NET, there's technically a runtime which interprets an IL and JITs out some code. It may allocate a big virtual memory arena but then not use it (hence the <1GB actual reserved/in use space). I know there are other open memory issues, but they focus on actual memory usage being high.

On the subject of it not exiting, that's surprising for a few reasons:

  • On startup, we monitor the parent process to try and exit when it does.
  • The editor can send a notification to us to signal a close.

jakebailey avatar Nov 06 '19 17:11 jakebailey

Yeah, I think I may not have been an issue and simply closing the overnight process was taking a long time and I assumed it wouldn't close itself. I've not been able to reproduce this again so I'm going to close and reopen it if it happens again.

CMLL avatar Nov 07 '19 17:11 CMLL

@jakebailey @MikhailArkhipov Found a bit of information on the case when the LS won't close. I'm using the insiders version of the Python Extension and noticed that the current switch between the old version and the new one left a LS process out of date open in the background. Unsure if is an LS or Python extension issue.

image

If i collapse those 0.4.105 process I notice that there are 2 of them, one with PID of 2487 and 526.

image

CMLL avatar Nov 12 '19 16:11 CMLL

This may be b/c LS didn't get shutdown event (or there is a bug). Host process id probably remained the same so code that tracks host lifetime didn't terminate LS either.

MikhailArkhipov avatar Nov 12 '19 16:11 MikhailArkhipov

I've noticed something else related to this bug. Doesn't seem to be tied to actually closing the VSCode instance in nature, but is an effect of it. I've resorted to work with the LS with an htop window open and several times I've noticed that when my VirtualMemory shoots up like crazy a second instance of VSCode shows up.

image

image

This comes accompanied with general freezing and bad performance of the LS, half parse of words and the autocompletion in general doesn't work. If I reload the VSCode instance, the currently working instance goes away but the one with really high virtual memory sticks around, which is what lead me to believe it was an issue when closing the LS instance.

CMLL avatar Dec 18 '19 23:12 CMLL

Just as another datapoint for now, I will try to investigate more:

The LS also does not terminate for me on macOS 10.15.2 even when I quit VSCode; I have to kill the process. I will try to post logs or debug info next time I work on python files, but it seems to happen pretty much every time.

The LS process also consumes 100% of one core and has fairly high memory usage.

I haven't really found any leads from poking around in palantir/python-language-server...

macOS 10.15.2

python-language-server 0.28.2 (I have this globally installed by pip, but VSCode probably installs their own somewhere too?)

Version: 1.41.1
Commit: 26076a4de974ead31f97692a0d32f90d735645c0
Date: 2019-12-18T14:57:51.166Z
Electron: 6.1.5
Chrome: 76.0.3809.146
Node.js: 12.4.0
V8: 7.6.303.31-electron.0
OS: Darwin x64 19.2.0

Name: Python
Id: ms-python.python
Version: 2020.1.58038
Publisher: Microsoft
VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=ms-python.python

mwilliammyers avatar Jan 23 '20 19:01 mwilliammyers

That's a different language server entirely, and our VS Code extension does not run it.

jakebailey avatar Jan 23 '20 20:01 jakebailey

Looks like Palantir https://github.com/palantir/python-language-server

MikhailArkhipov avatar Jan 23 '20 20:01 MikhailArkhipov

Sorry, I have both installed but the one that doesn't terminate when VSCode quits is definitely the VSCode one...

It constantly stays above 100% CPU usage even after I quit VSCode.

Here it is after VScode has been quit for about 5 minutes (I am using glances to search for Code or Microsoft to show that VSCode is not running): image

Again, not a huge deal—I will try to dig into it and see what is going on, I was just posting this for another data point as reference...

mwilliammyers avatar Jan 25 '20 00:01 mwilliammyers

It consistently happens under MacOS (Catalina 10.15.4) for me also. But trying to reproduce it I noticed that it only happens if I try working on a Python notebook in vscode. I.e. if I start vscode and say run my Python unit tests and then exit, then there is no Microsoft.Python.LanguageServer process running subsequently.

However if I do the same thing except subsequently open an ipynb file before exiting vscode, a process for ~/.vscode/extensions/ms-python.python-2020.4.76186/languageServer.0.5.45/Microsoft.Python.LanguageServer continues to run until I kill it.

Here's what the About menu says:

Version: 1.45.0 Commit: d69a79b73808559a91206d73d7717ff5f798f23c Date: 2020-05-07T15:57:33.467Z (4 days ago) Electron: 7.2.4 Chrome: 78.0.3904.130 Node.js: 12.8.1 V8: 7.8.279.23-electron.0 OS: Darwin x64 19.4.0

But I believe it's been an issue for me for a while.

daragallagher avatar May 12 '20 10:05 daragallagher

This happens specially when there is an update, the old LS sticks around.

dashesy avatar May 12 '20 17:05 dashesy

This is an issue for me whenever I open a ipynb on MacOS (Catalina).

akapocsi avatar May 12 '20 21:05 akapocsi

image

Just adding some data. I mostly see what others have described here. At the time of this screen, I had been looking to see what was eating my ram/swap. I closed vscode several minutes prior. This is Mojave 10.14.6 and current vscode.

Update - Once I sent a 15 to the process: image

Gary-Armstrong avatar May 20 '20 13:05 Gary-Armstrong

I am also seeing Python LanguageServer never closing, however it is not on MacOS but on Linux, through SSH remote (windows client). LS stops as expected when starting VSCode and stopping it shortly afterwards, but it hangs after working for a while (could not identify under which circumstances exactly).

fsteinmetz avatar May 20 '20 14:05 fsteinmetz

Same here on Windows10::1909. PythonLanguageServer does not stop when I close VScode or close all .ipynb tabs.

alex-rantos avatar Jun 12 '20 13:06 alex-rantos

Confirm that this exists on Ubuntu 20.04, using VSCode 1.46. Same experience as @fsteinmetz, but also when working locally, not only through SSH remote.

My lumberjack solution to this is to run a very poetic command pkill Microsoft. Needless to say, this is not a nice thing to write every day.

jrusnacko avatar Jun 15 '20 15:06 jrusnacko

We haven't had the bandwidth to properly investigate and reproduce this, sorry. The LS is supposed to be watching its parent process to know when to exit, and VS Code is supposed to be sending an exit command if it's exiting cleanly. From the htop screenshots, it appears to be stuck doing something and doesn't get around to that check, but it's hard to tell and I wasn't able to reproduce it the first time around.

jakebailey avatar Jun 15 '20 18:06 jakebailey

If there is a consistent repro, there is a way to attach debugger to the LS process as described here https://github.com/microsoft/python-language-server/blob/master/CONTRIBUTING.md#debugging-c-code-in-microsoft-python-language-server. Perhaps breaking there may reveal where is it stuck.

MikhailArkhipov avatar Jun 15 '20 19:06 MikhailArkhipov