Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Dynamic node2 debug protocol detection - #150

Merged
roblourens merged 10 commits into
masterfrom
dynamicNode2Debug
Jun 19, 2017
Merged

roblourens merged 10 commits into
masterfrom
dynamicNode2Debug

Conversation

@roblourens

@roblourens roblourens commented Jun 16, 2017 •

Copy link
Copy Markdown
Member

Fixes microsoft/vscode#25036. Follows the process proposed in that issue, using lsof on linux/mac and netstat on windows.

@roblourens

Copy link
Copy Markdown
Member Author

Andre Weinand (@weinand) please take a look

@weinand

Copy link
Copy Markdown
Contributor

roblourens thanks Rob, will do!

Comment thread src/node/extension/extension.ts Outdated
}

let determineDebugTypeP: Promise<string|null>;
if (config.request === 'attach' && typeof config.processId === 'string' && config.processId.trim() === '${command:PickProcess}') {

@weinand Andre Weinand (weinand) Jun 19, 2017 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The check for '${command:PickProcess}' shows the problematic aspect of the approach: instead of letting VS Code handle the variable substitution generically, the node-debug extension now does the substitution explicitly, before VS Code gets a chance for doing it. But I don't think that this will break anybody... so I'm not asking that we change this approach.

May be we should consider to check for the alternative command ${command:extension.pickNodeProcess} as well.

Comment thread src/node/extension/extension.ts Outdated
return config.port === INSPECTOR_PORT_DEFAULT ? 'inspector' :
config.port === LEGACY_PORT_DEFAULT ? 'legacy' :
config.protocol ? config.protocol :
detectProtocolForPid(pidNum);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I suggest to use some 'if' statements here...

Comment thread src/node/extension/extension.ts Outdated
return debugType;
});
} else {
determineDebugTypeP = determineDebugType(config);

@weinand Andre Weinand (weinand) Jun 19, 2017 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why is the behaviour of determineDebugType so different from pickProcessAndDetermineDebugType?
I tried to use "processId": "12345" instead of "processId": "${command:PickProcess}" in my launch config (where 12345 is the ID of a node 8 process that I could have picked via the picker as well) but this fails because determineDebugType falls back to "legacy" (and I don't see a need for this). I would expect that picking a process and specifying its ID behave identically.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm refactoring this a little to fix that case.

Comment thread src/node/extension/extension.ts Outdated
config.port = debugType === 'node2' ? INSPECTOR_PORT_DEFAULT : LEGACY_PORT_DEFAULT;
}

return debugType;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

When running two node 8 processes, sending SIGUSR1 to the second results in the (expected) message: "Starting inspector on 127.0.0.1:9229 failed: address already in use". As a consequence "lsof/netstat" cannot determine the port and the "debugType" above will be null. Currently there is no error message shown in VS Code (and the node 8 message is probably not always visible). So we should consider to improve the error reporting in the "startSession" command.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Error reporting needs work, but I don't know how to handle that particular case, because the process.kill call doesn't fail. I think the only sign of it failing is the stderr message which we can't read in this case.

@weinand Andre Weinand (weinand) left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I've reviewed the code and tried various scenarios on macOS, linux, and windows. Overall this works great, so feel free to merge.

@roblourens

Copy link
Copy Markdown
Member Author

Thanks!

@roblourens
roblourens merged commit 5867e90 into master Jun 19, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants