Skip to content

fix(cli): allow --inspect=localhost:0 to resolve hostnames - #34230

Merged
littledivy merged 5 commits into
mainfrom
orch/divybot-142
May 22, 2026
Merged

littledivy merged 5 commits into
mainfrom
orch/divybot-142

Conversation

@divybot

@divybot divybot commented May 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Node accepts hostnames in --inspect=..., --inspect-port=..., and
inspector.open(port, host), resolving them via DNS. Deno's inspector
flag parser and op_inspector_open only accepted IP-literal hosts, so
--inspect=localhost:0 failed at parse time.

  • Resolve hostnames via ToSocketAddrs in inspect_value_parser and
    op_inspector_open, preferring IPv4 results to match Node's resolver.
  • Add op_inspector_port. The process.debugPort getter consults it
    so userland sees the ephemeral port chosen by --inspect=...:0. An
    explicit process.debugPort = N assignment still wins, matching
    Node's mutable semantics.
  • For --inspect-port=N used without --inspect[-brk|-wait], Node
    updates process.debugPort but does not start the inspector. Deno
    doesn't surface --inspect-port as a runtime flag, so the node_shim
    translator injects the equivalent process.debugPort = N; assignment
    into the eval code used by -p/-e.
  • Enables parallel/test-inspector-port-zero.js in the node_compat
    config.

Closes denoland/orchid#142

Test plan

  • New unit test inspect_value_parser_resolves_hostnames in
    cli/args/flags.rs covers localhost:0, localhost:1234, and
    localhost.
  • New unit tests in libs/node_shim/lib.rs
    (test_translate_inspect_port_injects_debug_port_for_print and
    test_translate_inspect_port_does_not_inject_when_inspector_enabled).
  • tests/node_compat/runner/suite/test/parallel/test-inspector-port-zero.js
    now passes (verified across 5 consecutive runs).
  • Existing inspector tests still pass:
    test-inspector-debug-end.js, test-inspector-has-idle.js,
    test-inspector-promises.js, test-inspector-open.js,
    test-inspector-open-coverage.js,
    test-inspector-open-port-integer-overflow.js.
  • Existing inspector parser unit tests still pass:
    inspect_flag_parsing, inspect_wait, inspect_default_host,
    inspect_publish_uid_flag_parsing.
  • cargo clippy -p deno_node -p node_shim -p deno --bin deno --lib
    clean.

Node accepts hostnames in `--inspect=...`, `--inspect-port=...`, and
`inspector.open(port, host)`, resolving them via DNS. Deno's inspector
flag parser and `op_inspector_open` only accepted IP-literal hosts,
so `--inspect=localhost:0` failed at parse time.

Use `ToSocketAddrs` to resolve hostnames in both places, preferring
IPv4 results to match Node's resolver on most systems. Add an
`op_inspector_port` op that returns the actual bound port from the
inspector server URL, and use it from the `process.debugPort` getter
so userland sees the ephemeral port chosen by `--inspect=...:0`. An
explicit `process.debugPort = N` assignment still wins, matching
Node's mutable semantics.

For `--inspect-port=N` used without `--inspect[-brk|-wait]`, Node
updates `process.debugPort` but does not start the inspector. Deno
doesn't carry `--inspect-port` as a runtime flag, so the node_shim
translator injects the equivalent `process.debugPort = N;` assignment
into the eval code used by `-p`/`-e`.

Enables the upstream node_compat test
`parallel/test-inspector-port-zero.js`.

Closes denoland/orchid#142

Co-Authored-By: Divy Srivastava <me@littledivy.com>
@divybot divybot changed the title node compat: allow --inspect host localhost for inspector port-zero test fix(cli): allow --inspect=localhost:0 to resolve hostnames May 19, 2026
@divybot

divybot commented May 21, 2026

Copy link
Copy Markdown
Contributor Author

CI failure on test node_compat (3/3) release linux-x86_64 is the known flaky parallel/test-cluster-send-deadlock.js timeout (tracked in #34180) — unrelated to this PR. All other checks (including the rest of node_compat, specs, and unit tests) pass. Could a maintainer rerun the failed job?

@fibibot

fibibot commented May 22, 2026

Copy link
Copy Markdown
Contributor

node_compat::parallel::test-cluster-send-deadlock.js hit the known flake tracked in #34180, unrelated to this PR. Re-running the failed job.

@littledivy
littledivy merged commit b47520d into main May 22, 2026
269 of 271 checks passed
@littledivy
littledivy deleted the orch/divybot-142 branch May 22, 2026 17:58
turtletongue pushed a commit to turtletongue/deno that referenced this pull request May 23, 2026
## Summary

Node accepts hostnames in `--inspect=...`, `--inspect-port=...`, and
`inspector.open(port, host)`, resolving them via DNS. Deno's inspector
flag parser and `op_inspector_open` only accepted IP-literal hosts, so
`--inspect=localhost:0` failed at parse time.

- Resolve hostnames via `ToSocketAddrs` in `inspect_value_parser` and
  `op_inspector_open`, preferring IPv4 results to match Node's resolver.
- Add `op_inspector_port`. The `process.debugPort` getter consults it
  so userland sees the ephemeral port chosen by `--inspect=...:0`. An
  explicit `process.debugPort = N` assignment still wins, matching
  Node's mutable semantics.
- For `--inspect-port=N` used without `--inspect[-brk|-wait]`, Node
  updates `process.debugPort` but does not start the inspector. Deno
  doesn't surface `--inspect-port` as a runtime flag, so the node_shim
  translator injects the equivalent `process.debugPort = N;` assignment
  into the eval code used by `-p`/`-e`.
- Enables `parallel/test-inspector-port-zero.js` in the node_compat
  config.

Closes denoland/orchid#142

## Test plan

- New unit test `inspect_value_parser_resolves_hostnames` in
  `cli/args/flags.rs` covers `localhost:0`, `localhost:1234`, and
  `localhost`.
- New unit tests in `libs/node_shim/lib.rs`
  (`test_translate_inspect_port_injects_debug_port_for_print` and
  `test_translate_inspect_port_does_not_inject_when_inspector_enabled`).
-
`tests/node_compat/runner/suite/test/parallel/test-inspector-port-zero.js`
  now passes (verified across 5 consecutive runs).
- Existing inspector tests still pass:
  `test-inspector-debug-end.js`, `test-inspector-has-idle.js`,
  `test-inspector-promises.js`, `test-inspector-open.js`,
  `test-inspector-open-coverage.js`,
  `test-inspector-open-port-integer-overflow.js`.
- Existing inspector parser unit tests still pass:
  `inspect_flag_parsing`, `inspect_wait`, `inspect_default_host`,
  `inspect_publish_uid_flag_parsing`.
- `cargo clippy -p deno_node -p node_shim -p deno --bin deno --lib`
  clean.

Co-authored-by: divybot <divybot@users.noreply.github.com>
Co-authored-by: Divy Srivastava <me@littledivy.com>
littledivy added a commit to crowlKats/deno that referenced this pull request Jun 10, 2026
## Summary

Node accepts hostnames in `--inspect=...`, `--inspect-port=...`, and
`inspector.open(port, host)`, resolving them via DNS. Deno's inspector
flag parser and `op_inspector_open` only accepted IP-literal hosts, so
`--inspect=localhost:0` failed at parse time.

- Resolve hostnames via `ToSocketAddrs` in `inspect_value_parser` and
  `op_inspector_open`, preferring IPv4 results to match Node's resolver.
- Add `op_inspector_port`. The `process.debugPort` getter consults it
  so userland sees the ephemeral port chosen by `--inspect=...:0`. An
  explicit `process.debugPort = N` assignment still wins, matching
  Node's mutable semantics.
- For `--inspect-port=N` used without `--inspect[-brk|-wait]`, Node
  updates `process.debugPort` but does not start the inspector. Deno
  doesn't surface `--inspect-port` as a runtime flag, so the node_shim
  translator injects the equivalent `process.debugPort = N;` assignment
  into the eval code used by `-p`/`-e`.
- Enables `parallel/test-inspector-port-zero.js` in the node_compat
  config.

Closes denoland/orchid#142

## Test plan

- New unit test `inspect_value_parser_resolves_hostnames` in
  `cli/args/flags.rs` covers `localhost:0`, `localhost:1234`, and
  `localhost`.
- New unit tests in `libs/node_shim/lib.rs`
  (`test_translate_inspect_port_injects_debug_port_for_print` and
  `test_translate_inspect_port_does_not_inject_when_inspector_enabled`).
-
`tests/node_compat/runner/suite/test/parallel/test-inspector-port-zero.js`
  now passes (verified across 5 consecutive runs).
- Existing inspector tests still pass:
  `test-inspector-debug-end.js`, `test-inspector-has-idle.js`,
  `test-inspector-promises.js`, `test-inspector-open.js`,
  `test-inspector-open-coverage.js`,
  `test-inspector-open-port-integer-overflow.js`.
- Existing inspector parser unit tests still pass:
  `inspect_flag_parsing`, `inspect_wait`, `inspect_default_host`,
  `inspect_publish_uid_flag_parsing`.
- `cargo clippy -p deno_node -p node_shim -p deno --bin deno --lib`
  clean.

Co-authored-by: divybot <divybot@users.noreply.github.com>
Co-authored-by: Divy Srivastava <me@littledivy.com>
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