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

src: check if the script file exists before starting inspector #42673

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cola119
Copy link
Member

@cola119 cola119 commented Apr 9, 2022

Fixed #42600

Currently node --inspect-brk index.js will start the inspector and wait a connection event though index.js doesn't exist. And immediately after connected, node will throw Cannot find module error and wait to be disconnected.

This PR added the ability to check for the existence of the script file before an inspector agent is started. If the script is missing, inspector is not enabled and node module loader will throw MODULE_NOT_FUOND error.

v17.9.0 This PR
node --inspect no-exist.js Enable inspector agent & MODULE_NOT_FOUND error MODULE_NOT_FOUND error
node --inspect-brk no-exist.js Enable inspector agent MODULE_NOT_FOUND error
node inspect no-exist.js Enable inspector agent but commands fail MODULE_NOT_FOUND error in a child process
node --inspect Enable inspector agent Enable inspector agent
node --inspect-brk Enable inspector agent Enable inspector agent

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/startup

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Apr 9, 2022
@cola119 cola119 marked this pull request as draft April 9, 2022 23:20
@cola119 cola119 force-pushed the issue/42600 branch 2 times, most recently from c00fcdc to e735cf1 Compare April 16, 2022 06:00
@cola119 cola119 marked this pull request as ready for review April 16, 2022 06:01
@watilde watilde added the request-ci Add this label to start a Jenkins CI on a PR. label May 19, 2022
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label May 19, 2022
@nodejs-github-bot
Copy link
Collaborator

Copy link
Member

@legendecas legendecas left a comment

Choose a reason for hiding this comment

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

Agent::PauseOnNextJavascriptStatement assumes that the inspector agent is started with Agent::Start and Agent::client_ exists. Early break from Environment::InitializeInspector and not calling Agent::Start can break the assumption that if the process is started with --inspect-brk the agent must have been started.

Like say, we can crash the process with segment fault with the following setup:

// preload.js
require('fs').writeFileSync('./main.js', 'console.log("main")', 'utf8);

and run node with node --inspect-brk --require=./preload.js main.js with main.js not existing.

Maybe we can instead delay the wait for client connection to the time before we pause on next javascript statement?

match = true;
break;
}
if (/Debugger listening on/.test(stderr)) {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: can we assert that this statement is not present in the output?

@cola119 cola119 marked this pull request as draft June 17, 2022 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

node --inspect-brk index.js can be executed even though index.js does not exist
5 participants