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

Debugging fix #47083 #47671

Closed
wants to merge 7 commits into from
Closed

Debugging fix #47083 #47671

wants to merge 7 commits into from

Conversation

jarethtan
Copy link

What?

This fix closes #47083 issue.

Why?

Debugger crashes when --inspect=0.0.0.0:9229 was passed.
In order to expose a debugger from inside a Docker container, it has to listen on 0.0.0.0 instead of the default 127.0.0.1 IP address. To do that, we have to specify an inspect flag format of --inspect=0.0.0.0:9229. In the code:

const debugPort = (() => {
const debugPortStr =
process.execArgv
.find(
(localArg) =>
localArg.startsWith('--inspect') ||
localArg.startsWith('--inspect-brk')
)
?.split('=')[1] ??
process.env.NODE_OPTIONS?.match?.(
/--inspect(-brk)?(=(\S+))?( |$)/
)?.[3]
return debugPortStr ? parseInt(debugPortStr, 10) : 9229
})()

Passing NODE_OPTIONS=--inspect=0.0.0.0:9229 next dev into the debugPort function, It expects debugPortStr to be shaped like an integer. But if you use --inspect:0.0.0.0:9229, debugPortStr is now 0.0.0.0:9229, thus the parse fails and returns 0.

Then not long after, it tries using this 0 port and does +1 on it.

`--inspect${isDebuggingWithBrk ? '-brk' : ''}=${debugPort + 1}`

Causing this warning warn - the --inspect option was detected, the Next.js server should be inspected at port 1.

Then a subsequent error /usr/bin/node: must be 0 or in range 1024 to 65535.

How?

The recommendation is to create a function transformInspectFlagForNextAvailablePort() that returns an entire string input. Four different types of inspect flag inputs are accepted for this function and the actions are as follows:

  1. Input format --inspect=0.0.0.0:9229. function shall accept inspect flag with the port number modified to +1 on the user specified port number (In this case it is 9229). Resulting port will be 9230. Function will return --inspect=0.0.0.0:9230.
  2. Input format --inspect=0.0.0.0. function shall accept inspect flag with IP address specified. Since port is not specified, a default port number of 9229 is allocated and +1 to it. Resulting port will be 9230. Function will return --inspect=0.0.0.0:9230.
  3. Input format --inspect=9229. function shall accept inspect flag with port specified. Since IP is not specified, a default IP address of 127.0.0.1 is allocated and +1 to it. Function will return --inspect=127.0.0.1:9230.
  4. Input format --inspect. function shall accept inspect flag with port specified. Since IP and Port are not specified, a default IP address of 127.0.0.1 and a default port number of 9229 are allocated. Default port (9229) is modified to +1 and resulting port will be 9230. Function will return --inspect=127.0.0.1:9230.

Try out the function in the following Link

Fixes

Returns the correct inspect flag string format to process.execArgv when docker IP address 0.0.0.0 is included in the inspect flag.

Note: I have tried running pnpm lint however it fails with an error as follows

Lint console output
@jarethtan ➜ /workspaces/next.js (debugging_fix) $ pnpm lint

> nextjs-project@0.0.0 lint /workspaces/next.js
> run-p test-types lint-typescript prettier-check lint-eslint lint-language


> nextjs-project@0.0.0 lint-typescript /workspaces/next.js
> turbo run typescript


> nextjs-project@0.0.0 lint-eslint /workspaces/next.js
> eslint . --ext js,jsx,ts,tsx --max-warnings=0 --config .eslintrc.json --no-eslintrc


> nextjs-project@0.0.0 test-types /workspaces/next.js
> tsc


> nextjs-project@0.0.0 prettier-check /workspaces/next.js
> prettier --check .


> nextjs-project@0.0.0 lint-language /workspaces/next.js
> alex .

Checking formatting...
.github/actions/issue-on-comment/index.js• Packages in scope: @next/bundle-analyzer, @next/codemod, @next/env, @next/eslint-plugin-next, @next/font, @next/mdx, @next/plugin-storybook, @next/polyfill-module, @next/polyfill-nomodule, @next/react-dev-overlay, @next/react-refresh-utils, @next/swc, @turbo/pack-test-harness, @vercel/turbopack-next, bench-production, create-next-app, eslint-config-next, next, next-dev-tests
• Running typescript in 19 packages
• Remote caching disabled
@next/font:typescript: Skipping cache check for @next/font#typescript, outputs have not changed since previous run.
@next/font:typescript: cache hit, replaying output e6e2216ad4f2c0a5
@next/react-dev-overlay:typescript: Skipping cache check for @next/react-dev-overlay#typescript, outputs have not changed since previous run.
@next/react-dev-overlay:typescript: cache hit, replaying output 8f093f92c8f287c2
next:typescript: cache miss, executing 319ed840e88377bb
@next/font:typescript: 
@next/font:typescript: > @next/font@13.2.5-canary.12 typescript /workspaces/next.js/packages/font
@next/font:typescript: > tsec --noEmit -p tsconfig.json
@next/font:typescript: 
@next/react-dev-overlay:typescript: 
@next/react-dev-overlay:typescript: > @next/react-dev-overlay@13.2.5-canary.12 typescript /workspaces/next.js/packages/react-dev-overlay
@next/react-dev-overlay:typescript: > tsec --noEmit -p tsconfig.json
@next/react-dev-overlay:typescript: 
next:typescript: 
next:typescript: > next@13.2.5-canary.12 typescript /workspaces/next.js/packages/next
next:typescript: > tsec --noEmit
next:typescript: 
examples/amp-first/public/manifest.jsonKilled
 ELIFECYCLE  Command failed with exit code 137.
examples/api-routes-apollo-server-and-client-auth/apollo/client.tsx ELIFECYCLE  Command failed.
 ELIFECYCLE  Command failed.
 ELIFECYCLE  Command failed.
 ELIFECYCLE  Command failed.
ERROR: "lint-eslint" exited with 1.
 ELIFECYCLE  Command failed with exit code 1.
next:typescript:  ELIFECYCLE  Command failed.

However I am unable to trace the bug and find out what is the linting error. I tried pnpm lint--fix and ran pnpm lint but the problem is still there

Copy link
Member

@ijjk ijjk left a comment

Choose a reason for hiding this comment

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

Closing in favor of #48019 thanks for the PR though!

@ijjk ijjk closed this May 23, 2023
ijjk added a commit that referenced this pull request May 23, 2023
## Bug

This fix closes #47083 issue 
This fix closes #47561 issue
This fix closes #48376 issue
**Invalid repetition PRs:** #47671 (this PR changing expired code)
(This issue still exist on
[v13.4.3-canary.1](https://github.com/vercel/next.js/releases/tag/v13.4.3-canary.1)

- [x] Related issues linked using `fixes #number`

### What?
When running `NODE_OPTIONS='--inspect' next dev`, 
the render server didn't start with `--inspect`. 
In some cases, 
the `--inspect` flag will be passed when `__NEXT_DISABLE_MEMORY_WATCHER`
was set.

### Why?
Since #47208 revamped some startup processes, the `NODE_OPTIONS`
environment parameter is not passed down to the render server worker.

### How?
Just add back the original startup process.


![image](https://user-images.githubusercontent.com/14261588/230398898-791e6909-6f4c-493b-937d-058a7b788849.png)


link NEXT-1176

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
hydRAnger pushed a commit to hydRAnger/next.js that referenced this pull request Jun 12, 2023
## Bug

This fix closes vercel#47083 issue 
This fix closes vercel#47561 issue
This fix closes vercel#48376 issue
**Invalid repetition PRs:** vercel#47671 (this PR changing expired code)
(This issue still exist on
[v13.4.3-canary.1](https://github.com/vercel/next.js/releases/tag/v13.4.3-canary.1)

- [x] Related issues linked using `fixes #number`

### What?
When running `NODE_OPTIONS='--inspect' next dev`, 
the render server didn't start with `--inspect`. 
In some cases, 
the `--inspect` flag will be passed when `__NEXT_DISABLE_MEMORY_WATCHER`
was set.

### Why?
Since vercel#47208 revamped some startup processes, the `NODE_OPTIONS`
environment parameter is not passed down to the render server worker.

### How?
Just add back the original startup process.


![image](https://user-images.githubusercontent.com/14261588/230398898-791e6909-6f4c-493b-937d-058a7b788849.png)


link NEXT-1176

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 23, 2023
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.

[NEXT-1176] Debugging with non-localhost address stopped working
2 participants