Skip to content

fix: increment inspector port for IPv6 hosts - #2636

Merged
abetomo merged 3 commits into
tj:developfrom
20ns:fix/ipv6-inspector-port
Oct 5, 2026
Merged

abetomo merged 3 commits into
tj:developfrom
20ns:fix/ipv6-inspector-port

Conversation

@20ns

@20ns 20ns commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Commander increments the Node inspector port when spawning an executable subcommand, but the host patterns exclude colons. Bracketed IPv6 hosts therefore bypass the incrementer, and the child tries to use the parent's port.

For example, running node --inspect=[::1]:19340 tests/fixtures/inspect.js sub on develop prints Starting inspector on ::1:19340 failed: address already in use. With this fix, the child starts its inspector on [::1]:19341.

Recognise bracketed IPv6 hosts in the existing shared parser, both with an explicit port and with the default port. Add separate regressions for IPv6 hosts with and without an explicit port using the existing executable-subcommand test helper. No dependencies or API changes.

Validation:

  • The regression fails before the fix and passes afterward.
  • All 1,427 runtime tests and TypeScript tests pass on Node 22.22.0, 24.21.0, and 26.10.0.
  • pnpm check passes, including JavaScript and TypeScript checks, ESLint, and Prettier.
  • The real parent/child reproduction opens separate IPv6 inspector ports after the fix.
  • Checked all four supported inspector flags with IPv6, IPv4, hostname, default-port, and port-zero inputs.

Suggested changelog entry: Fix incrementing the Node inspector port for IPv6 hosts when spawning executable subcommands.

Prepared with AI assistance. The complete diff was reviewed and the checks above were run before submission.

@shadowspawn

Copy link
Copy Markdown
Collaborator

Can you supply a good (authoritative and easy to read) reference for Bracketed IPv6 host addresses?

The regular expression is pretty opaque. A brief comment explaining the point of the regexp is needed.

test('when --inspect uses an IPv6 host then bump port', (t) => {
const { spawnSpy } = makeSpies(t);
const program = makeProgram();
process.execArgv = ['--inspect=[::1]', '--inspect=[::1]:100'];

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is having multiple inspect ports in a single call a valid use of the CLI?

I expected these to be in separate calls (and separate tests).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point. I combined the two cases to keep the test small, but separate tests would reflect actual usage better. I'll split them into an IPv6 host-only case and an IPv6 host-with-port case.

@20ns

20ns commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. RFC 3986, section 3.2.2 specifies square brackets around IPv6 host literals. For [::1]:19340, the brackets separate the address's internal colons from the port separator.

I'll add a brief comment explaining that the host pattern matches either a bracketed IPv6 address or a hostname/IPv4 address without colons, with the optional port handled separately.

@shadowspawn

Copy link
Copy Markdown
Collaborator

I reworked the comments to remind myself what is happening, simpler than sending you lots of suggestions or replacements. (First time I have done a commit direct to a PR!)

@shadowspawn shadowspawn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@abetomo
abetomo merged commit 6320660 into tj:develop Oct 5, 2026
11 checks passed
@shadowspawn shadowspawn added the pending release Merged into a branch for a future release, but not released yet label Oct 5, 2026
@shadowspawn shadowspawn removed the pending release Merged into a branch for a future release, but not released yet label Nov 7, 2026
@shadowspawn

Copy link
Copy Markdown
Collaborator

Released in Commander v15.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants