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

Cannot start node inspector: "address already in use" #11030

Closed
ramijarrar opened this issue Mar 13, 2020 · 5 comments · Fixed by #11041
Closed

Cannot start node inspector: "address already in use" #11030

ramijarrar opened this issue Mar 13, 2020 · 5 comments · Fixed by #11041

Comments

@ramijarrar
Copy link

ramijarrar commented Mar 13, 2020

Bug report

After upgrading from Next 9.2.2 -> 9.3.0 the node inspector fails to start (crashing the Next process) with the error "Starting inspector on 0.0.0.0:9229 failed: address already in use".

None of the suggestions offered in #10610 or #9027 have helped. Have also tested with Next 9.3.1-canary.3 and noted the same issue occurs.

To Reproduce

Steps to reproduce the behavior:

  1. Run npx create-next-app
  2. Add "dev": "NODE_OPTIONS='--inspect' next" to scripts
  3. Run npm run dev
  4. See error

Expected behavior

The node inspector starts normally without crashing the Next process.

System information

  • OS: macOS 10.15.3
  • Version of Next.js: 9.3.0+
@vvo
Copy link
Member

vvo commented Mar 13, 2020

I confirm this new behaviour, we need to figure out what are the different actual nodejs processes launched behind the next command and then see how we can fix that. Maybe by re-introducing the --inspect flag instead or manipulating process.env.NODE_OPTIONS (😱) in the main cli tool.

I had a look in the next source code but could not figure out what are the actual processes.

@vvo
Copy link
Member

vvo commented Mar 13, 2020

Update: I found the issue. When running next dev, the file next-dev-server.ts will launch a subprocess using jest-worker here: https://github.com/zeit/next.js/blob/6997b0236b68fd7c8f5395003c99a719974cc404/packages/next/server/next-dev-server.ts#L83-L91

As a result, another Node.js process is spawned with the same process.env.NODE_OPTIONS='--inspect' and will also try to start a debugger on the same port than the one the main next dev command started just earlier.

This is a known issue from Node.js but there's not much that they will do about it for good reasons, see nodejs/node#9435 (comment)

But we can do something, I tried it and it works, just remove any --inspect flag from NODE_OPTIONS passed to the worker and done, see the PR: #11041

@cadamsdev
Copy link

Related issue #11095

@vvo
Copy link
Member

vvo commented Mar 19, 2020

Just updated the PR for that to solve it.

timneutkens pushed a commit that referenced this issue Apr 1, 2020
* fix(debugging): do not pass NODE_OPTIONS='--inspect' to subprocesses

fixes #11030

* fix(debugger): use a regex to remove bad NODE_OPTIONS flags

Co-authored-by: Alec Larson <alec.stanford.larson@gmail.com>
@Timer Timer removed this from the 10.x.x milestone Nov 16, 2020
@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants