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

Dynamic node2 debug protocol detection #150

Merged
merged 10 commits into from
Jun 19, 2017
Merged

Dynamic node2 debug protocol detection #150

merged 10 commits into from
Jun 19, 2017

Conversation

roblourens
Copy link
Member

@roblourens roblourens commented Jun 16, 2017

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

@roblourens
Copy link
Member Author

@weinand please take a look

@weinand weinand added this to the June 2017 milestone Jun 16, 2017
@weinand
Copy link
Contributor

weinand commented Jun 16, 2017

@roblourens thanks Rob, will do!

@@ -388,15 +386,31 @@ function startSession(config: any): StartSessionResult {
}
}

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

@weinand weinand Jun 19, 2017

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.

return config.port === INSPECTOR_PORT_DEFAULT ? 'inspector' :
config.port === LEGACY_PORT_DEFAULT ? 'legacy' :
config.protocol ? config.protocol :
detectProtocolForPid(pidNum);
Copy link
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...

return debugType;
});
} else {
determineDebugTypeP = determineDebugType(config);
Copy link
Contributor

@weinand weinand Jun 19, 2017

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
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.

config.port = debugType === 'node2' ? INSPECTOR_PORT_DEFAULT : LEGACY_PORT_DEFAULT;
}

return debugType;
Copy link
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
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.

Copy link
Contributor

@weinand weinand left a comment

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.

@weinand weinand assigned roblourens and unassigned weinand Jun 19, 2017
@roblourens
Copy link
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