Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure node-based debug adapters spawn same node exec as Theia #7294

Merged
merged 1 commit into from
Mar 12, 2020

Conversation

veredcon
Copy link
Contributor

@veredcon veredcon commented Mar 8, 2020

Signed-off-by: Vered Constantin vered.constantin@sap.com

Sometimes the container/machine running Theia has more than one node executable available.

The node executable used to run Theia should also be used to run node-based debug adapters; whereas, another node executable can be used to run/debug user applications.

Debug adapters specify their runtime in their corresponding package.json file (e.g. link):

"contributes": {
  "debuggers": [
    {
       "runtime": "node"
    }
}

The debug adapter typically does not specify the full path of the node executable, which means that Theia uses the first node executable on the PATH environment variable to spawn the debug adapter. However, this might not be the same node executable that was used to run Theia.

For us at SAP, this is critical, as we expose node executables to the Theia container, and those executables might run remotely on other containers that have no access to the debug adapter code (which resides on the Theia container).

This pull request ensures that if a debug adapter doesn't specify a fully qualified node runtime, theia would spawn the debug adapter using the same node executable that was used to launch Theia.

This change should not adversely affect existing flows, but rather add support for the requirement detailed above.

How to Test:

  1. Use nvm to install two node versions. For example 10.16.0 and 12.2.0
  2. Set 12.2.0 as active version: nvm use 12.2.0
  3. Launch theia using different node version from the active node version on the PATH:
    can do this by adding:
    "runtimeExecutable": "c:/Users/<>/AppData/Roaming/nvm/v10.16.0/node.exe"
    to the launch configuration of "Launch Browser Backend".
  4. Test debug node application works. The debug node adapter process should use node v10.16.10
    same as theia process and not the node version as configured in PATH.
    I debugged the flow to verify this and also used Windows PowerShell with the following
    command:
    get-process | get-item -erroraction silentlycontinue | format-table name, directory | grep node
    I could see processes from directory "C:\Users<>\AppData\Roaming\nvm\v10.16.0" but without
    this PR I see that after clicking "Launch" on my node application and the application is running,
    there are node processes from the PATH "C:\Program Files\nodejs"

This issue is similar to #5492 and #5508.

Copy link
Member

@vince-fugnitto vince-fugnitto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@veredcon thank you for your first contribution!
There are a couple of things that need to be completed before we can accept your changes:

Also, it looks like the following code as-is has errors:
https://travis-ci.com/eclipse-theia/theia/jobs/295775177#L705-L707

@akosyakov akosyakov added the debug issues that related to debug functionality label Mar 9, 2020
@akosyakov akosyakov requested a review from tolusha March 9, 2020 08:06
@akosyakov
Copy link
Member

@tolusha Could you give a look please? You know this area better, thank you!

@akosyakov
Copy link
Member

@veredcon Please update the description to reflect our template: https://github.com/eclipse-theia/theia/blob/master/doc/pull-requests.md#pr-template

How to test section is important. It shows us that you took time to tests for regressions and document a way for others how to do it for next time when we have to change this area.

@kittaakos
Copy link
Contributor

Please keep in mind, if we go with the proposed change, we will use Node.js bundled with electron. Which is not what you want either.

@veredcon
Copy link
Contributor Author

veredcon commented Mar 9, 2020

Thanks @kittaakos for your review!
Why is it an issue? Do you have a suggestion?
Thanks!

@kittaakos
Copy link
Contributor

kittaakos commented Mar 9, 2020

Why is it an issue?

Not an issue but not necessarily what you want. For example, If you use mvn nvm and you have Node.js 10.15.3 on the PATH and you start an electron application you won't ever use your Node.js 10.15.3 from the PATH as you would expect, but you will use the Node.js v10.11.0 which is shipped with electron@4.2.12.

edit: mvn -> nvm

@akosyakov
Copy link
Member

Please keep in mind, if we go with the proposed change, we will use Node.js bundled with electron. Which is not what you want either.

@kittaakos But only by default? A user still can change launch configuration to configure another npm version: https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_multi-version-support

I wonder which version VS Code is using by default and how it gets it.

@kittaakos
Copy link
Contributor

I wonder which version VS Code is using by default and how it gets it.

Good point, the tiny research should be part of the PR.

@akosyakov
Copy link
Member

akosyakov commented Mar 9, 2020

Actually ignore what I've referenced. Referenced version is to be used by the debug adapter process to run a user program. A PR is about the node for the debug adapter process itself. Any node which can run node debug adapter should work. I would say we have to test it against Electron and if it works then it should be fine.

@veredcon
Copy link
Contributor Author

veredcon commented Mar 9, 2020

Hi @akosyakov - I've tested it with Electron and was able to debug node application successfully.

@akosyakov
Copy link
Member

ok, will test tomorrow, if nobody does it before

Signed-off-by: Vered Constantin <vered.constantin@sap.com>
Copy link
Member

@akosyakov akosyakov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good, thank you for clean up!

I've verified that node based debug adapters are still working for electron and browser targets.

@akosyakov akosyakov merged commit 07d0133 into eclipse-theia:master Mar 12, 2020
@veredcon
Copy link
Contributor Author

Thank you very much for your review and responsiveness!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
debug issues that related to debug functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants