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

Provide stdout and stderr from utility process and adopt in extension host #155987

Closed
alexdima opened this issue Jul 22, 2022 · 2 comments · Fixed by #161027
Closed

Provide stdout and stderr from utility process and adopt in extension host #155987

alexdima opened this issue Jul 22, 2022 · 2 comments · Fixed by #161027
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug confirmed Issue has been confirmed by VS Code Team member extension-host Extension host issues insiders-released Patch has been released in VS Code Insiders plan-item VS Code - planned item for upcoming sandbox Running VSCode in a node-free environment verified Verification succeeded

Comments

@alexdima
Copy link
Member

  • configure "extensions.experimental.useUtilityProcess": true
  • run `Developer: Show Running Extensions”
  • press the black circle icon in the editor title
  • this should enable inspecting the extension host and start profiling
  • this requires a restart because this method for UtilityProcess extension hosts is not working similarly to this method for regular nodejs extension host
@alexdima alexdima added this to the July 2022 milestone Jul 22, 2022
@alexdima alexdima added the sandbox Running VSCode in a node-free environment label Jul 22, 2022
@deepak1556 deepak1556 added bug Issue identified by VS Code Team member as probable bug extension-host Extension host issues confirmed Issue has been confirmed by VS Code Team member labels Jul 23, 2022
@deepak1556 deepak1556 modified the milestones: July 2022, August 2022 Jul 26, 2022
@bpasero bpasero mentioned this issue Jul 27, 2022
3 tasks
@deepak1556
Copy link
Collaborator

Update:

I was able to confirm that SIGUSR1 signal handlers are installed by Node.js inside the utility process via https://github.com/nodejs/node/blob/main/src/inspector_agent.cc#L92-L138

Also, process._debugProcess() action is indeed invoked via https://github.com/microsoft/vscode/blob/main/src/vs/platform/extensions/electron-main/extensionHostStarter.ts#L371-L392, to confirm

  • Make the following when running out of sources so that inspector does not get started on startup
diff --git a/src/vs/platform/environment/common/environmentService.ts b/src/vs/platform/environment/common/environmentService.ts
index d90cbc60fef..32ff30de6da 100644
--- a/src/vs/platform/environment/common/environmentService.ts
+++ b/src/vs/platform/environment/common/environmentService.ts
@@ -270,7 +270,7 @@ export function parsePtyHostPort(args: NativeParsedArgs, isBuild: boolean): IDeb
 
 function parseDebugParams(debugArg: string | undefined, debugBrkArg: string | undefined, defaultBuildPort: number, isBuild: boolean, debugId?: string, environmentString?: string): IExtensionHostDebugParams {
        const portStr = debugBrkArg || debugArg;
-       const port = Number(portStr) || (!isBuild ? defaultBuildPort : null);
+       const port = Number(portStr) || null;
        const brk = port ? Boolean(!!debugBrkArg) : false;
        let env: Record<string, string> | undefined;
        if (environmentString) {
  • .\scripts\code.sh
  • Developer: Show running extensions and click profile action
  • Now see main process console output which will now print
Debugger listening on ws://127.0.0.1:61222/fa9f6ced-bf9b-49a1-ba32-30690c6ccbfc
For help, see: https://nodejs.org/en/docs/inspector

The problem is that we try to obtain the inspector port for the above action from the stdout/stderr of the extension host process in

if (!this._inspectPort) {
this._inspectPort = Number(inspectorUrlMatch[2]);
this._onDidSetInspectPort.fire();
}

Since we current don't support stdout and stderr events for the utility process, we end up with empty inspector ports even though the inspector is started leading to failed profile action which ends up triggering the fallback. Maybe a temporary fix would be to read from the main process stdout. I will see if UtilityProcess.stdout, UtilityProcess.stderr can be implemented to make life easier.

@bpasero
Copy link
Member

bpasero commented Aug 12, 2022

I will see if UtilityProcess.stdout, UtilityProcess.stderr can be implemented to make life easier.

👍 . I had a brief look and it seems we listen to output and stderr not only for the purpose of obtaining the inspect port, but also to observe output and print it in general:

const onStdout = this._handleProcessOutputStream(this._extensionHostProcess.onStdout);
const onStderr = this._handleProcessOutputStream(this._extensionHostProcess.onStderr);
const onOutput = Event.any(
Event.map(onStdout.event, o => ({ data: `%c${o}`, format: [''] })),
Event.map(onStderr.event, o => ({ data: `%c${o}`, format: ['color: red'] }))
);

So I think we need this anyway, not just for debugging purposes. I wonder if this could also impact extension developers that want to log messages...

@bpasero bpasero changed the title UtilityExtensionHostProcess.enableInspectPort does not work Utility process does not support stdout and stderr Aug 12, 2022
@bpasero bpasero assigned deepak1556 and unassigned deepak1556 and alexdima Aug 12, 2022
@bpasero bpasero self-assigned this Sep 1, 2022
@bpasero bpasero changed the title Utility process does not support stdout and stderr Provide stdout and stderr from utility process and adopt in extension host Sep 1, 2022
@bpasero bpasero added the plan-item VS Code - planned item for upcoming label Sep 1, 2022
@vscodenpa vscodenpa added unreleased Patch has not yet been released in VS Code Insiders insiders-released Patch has been released in VS Code Insiders and removed unreleased Patch has not yet been released in VS Code Insiders labels Sep 16, 2022
@bpasero bpasero added the verified Verification succeeded label Sep 30, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Oct 31, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug confirmed Issue has been confirmed by VS Code Team member extension-host Extension host issues insiders-released Patch has been released in VS Code Insiders plan-item VS Code - planned item for upcoming sandbox Running VSCode in a node-free environment verified Verification succeeded
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants