eclipse-theia / theia

Eclipse Theia is a cloud & desktop IDE framework implemented in TypeScript.
http://theia-ide.org
Eclipse Public License 2.0
19.94k stars 2.49k forks source link

Language server of VSCode's C/C++ plugin does not stop when theia exit #5899

Open a1994846931931 opened 5 years ago

a1994846931931 commented 5 years ago

Description

VSCode's C/C++ plugin is working pretty well on theia now. But if one stops theia and then relaunch it, an error will be shown which says

root ERROR Uncaught Exception:  Error: ETXTBSY: text file is busy, open '/tmp/vscode-unpacked/cpptools-linux.vsix/extension/bin/Microsoft.VSCode.CPP.Extension.linux'
root ERROR Error: ETXTBSY: text file is busy, open '/tmp/vscode-unpacked/cpptools-linux.vsix/extension/bin/Microsoft.VSCode.CPP.Extension.linux'

and the plugin will not work at all. I can only have it work again either by removing /tmp/vscode-unpacked/cpptools-linux.vsix folder or by killing all the related plugin processes that run in the background even after theia is stopped.

Reproduction Steps

  1. Download master theia (in my case, the commit ID is 66976d0f29064f36f02d0090040828848da1a79e)
  2. Remove "@theia/cpp": "^0.9.0", dependency from examples/browser/package.json and compile theia
  3. Download VSCode's C/C++ plugin (https://github.com/microsoft/vscode-cpptools/releases/download/0.24.1/cpptools-linux.vsix) and put it into the plugins folder
  4. Launch theia. Open a C/C++ project and check for functions like auto-completion.
  5. Stop theia and check for the unstopped language server by running ps aux | grep CPP (linux)
  6. Re-run theia and you'll see the error information. Open a C/C++ project and you'll notice that it does not work again.

NOTE: Step 4 is necessary. If no C/C++ project is opened, the language server will stop as expected.

OS and Theia version: Ubuntu 18.04 Theia 66976d0f29064f36f02d0090040828848da1a79e

Diagnostics: No further diagnostic is available currently.

akosyakov commented 5 years ago

@a1994846931931 thanks for the reporting? Do you want to have a look at it?

a1994846931931 commented 5 years ago

@a1994846931931 thanks for the reporting? Do you want to have a look at it?

Yes, sure. Don't know what I can do, but I'm working on it.

akosyakov commented 5 years ago

Yes, sure. Don't know what I can do, but I'm working on it.

oh, me neither, it needs some debugging, but pretty sure that you will figure it out

a1994846931931 commented 5 years ago

Diagnostics Update: The problem is caused by that the language server is not correctly shut down, and it would relaunch 4 times when it's killed. The correct way to have it shut down is to call the plugin's "deactivate" function. But theia currently doesn't call the "deactivate" function when it exists.

akosyakov commented 5 years ago

It seems to be called here: https://github.com/theia-ide/theia/blob/d9bb466013049e272666bdbe3aee60d74ecd30f3/packages/plugin-ext/src/hosted/node/hosted-plugin-process.ts#L131

akosyakov commented 5 years ago

Could you try to revert https://github.com/theia-ide/theia/commit/797db759bcdde66c8bbabf2ab0b041bc7d887d30 and see whether it helps?

My assumption is that main process exits without terminating the plugin host process properly at all.

a1994846931931 commented 5 years ago

@akosyakov Hi! I added the line this.hostedPluginProcess.terminatePluginServer(); back here, https://github.com/theia-ide/theia/blob/797db759bcdde66c8bbabf2ab0b041bc7d887d30/packages/plugin-ext/src/hosted/node/hosted-plugin.ts#L90-L92

so that it becomes

 private terminatePluginServer(): void { 
     this.hostedPluginProcess.terminatePluginServer();
     this.hostedPluginProcess.markPluginServerTerminated(); 
 } 

but it doesn't work. It seems that function terminatePluginServer in HostedPluginSupport isn't called at all, when theia exists.

akosyakov commented 5 years ago

Usually we follow the pattern that a child process listen to whether parent process exists, if it does not then it exits as well, gracefully. We need to apply it for the plugin system as well. @theia-ide/plugin-system Is there any concerns?

tsmaeder commented 5 years ago

@akosyakov the approach is OK for a local plugin host process, but in Che we run plugin host processes remotely. Maybe an approach detecting connection loss would work better accross both scenarios?

akosyakov commented 5 years ago

@tsmaeder I thought you run Theia instance in each side container which spawns the plugin host process?

tsmaeder commented 5 years ago

We run a "partial" theia instance, but that just bumps the problem up to that theia instance: when does it go away? Btw: what does "stop Theia" mean in that instance? Killing the back end or closing a browser window?

akosyakov commented 5 years ago

It means when Theia instance (backend) is terminated somehow. I think in your case it would be also useful to terminate the plugin host process gracefully if "partial" theia instance is gone.