Repository navigation
fix(cli): allow --inspect=localhost:0 to resolve hostnames - #34230
Merged
Merged
Conversation
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>
littledivy
approved these changes
May 20, 2026
Contributor
Author
|
CI failure on |
Contributor
|
|
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Node accepts hostnames in
--inspect=...,--inspect-port=..., andinspector.open(port, host), resolving them via DNS. Deno's inspectorflag parser and
op_inspector_openonly accepted IP-literal hosts, so--inspect=localhost:0failed at parse time.ToSocketAddrsininspect_value_parserandop_inspector_open, preferring IPv4 results to match Node's resolver.op_inspector_port. Theprocess.debugPortgetter consults itso userland sees the ephemeral port chosen by
--inspect=...:0. Anexplicit
process.debugPort = Nassignment still wins, matchingNode's mutable semantics.
--inspect-port=Nused without--inspect[-brk|-wait], Nodeupdates
process.debugPortbut does not start the inspector. Denodoesn't surface
--inspect-portas a runtime flag, so the node_shimtranslator injects the equivalent
process.debugPort = N;assignmentinto the eval code used by
-p/-e.parallel/test-inspector-port-zero.jsin the node_compatconfig.
Closes denoland/orchid#142
Test plan
inspect_value_parser_resolves_hostnamesincli/args/flags.rscoverslocalhost:0,localhost:1234, andlocalhost.libs/node_shim/lib.rs(
test_translate_inspect_port_injects_debug_port_for_printandtest_translate_inspect_port_does_not_inject_when_inspector_enabled).tests/node_compat/runner/suite/test/parallel/test-inspector-port-zero.jsnow passes (verified across 5 consecutive runs).
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.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 --libclean.