Skip to content

inspector: support attaching to a running process in probe mode - #67201

Open
joyeecheung wants to merge 1 commit into
nodejs:mainfrom
joyeecheung:probe-attach-7
Open

joyeecheung wants to merge 1 commit into
nodejs:mainfrom
joyeecheung:probe-attach-7

Conversation

@joyeecheung

@joyeecheung joyeecheung commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Probe mode currently only launches a new process from the entry point script. This change lets it attach to an already-running process, so a long-lived application can be inspected without restarting it.

Running node inspect --probe without specifying an entry point script instructs Node.js to attach to a running Node.js process and probe. The way attaching is done is specified through command line arguments:

  • --pid <pid> activates the target's inspector (if it's not already activated) and connects to it.
  • --host <host> and --port <port> specify an address where an inspector is listening. The host defaults to 127.0.0.1 and the port defaults to 9229.

When the session ends, probe mode resumes and detaches instead of killing a process it does not own. The report now includes a top-level target field describing what was probed, and each probe contains a locations field about where it bound.

An attach session ends when a probe reaches --max-hit (reported as completed), when the target finishes on its own (completed, or miss with the pending probes, and the target is then allowed to exit), or when --timeout fires (reported as timeout, the probing process exit with 0 and reports the hits recorded so far).

--timeout now is also applied to the startup phase in both modes, so a target that never responds before the breakpoints are bound is reported as an error instead of hanging.

# Probing a process by PID, which may not already have the inspector listening.
# End the probing session when the specified probe is reached 5 times.
$ node inspect --probe app.js:42 --expr "req.url" --max-hit 5 --pid 12345

# Probing a process that's already listening for inspector connections at 127.0.0.1:9229.
# End the probing session when the specified timeout is reached.
$ node inspect --probe app.js:42 --expr "req.url" --timeout 50000 --host 127.0.0.1 --port 9229

@nodejs-github-bot nodejs-github-bot added debugger Issues and PRs related to the Node.js command-line debugger. needs-ci PRs that need a full CI run. labels Nov 2, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@codecov

codecov Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 79.76540% with 69 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.71%. Comparing base (1d3835e) to head (c2881e9).
⚠️ Report is 68 commits behind head on main.

Files with missing lines Patch % Lines
lib/internal/debugger/inspect_probe.js 76.84% 62 Missing and 4 partials ⚠️
lib/internal/debugger/inspect.js 62.50% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #67201      +/-   ##
==========================================
+ Coverage   90.65%   90.71%   +0.05%     
==========================================
  Files         797      797              
  Lines      278780   279168     +388     
  Branches    53611    53704      +93     
==========================================
+ Hits       252739   253242     +503     
+ Misses      16385    16291      -94     
+ Partials     9656     9635      -21     
Files with missing lines Coverage Δ
lib/internal/debugger/inspect_client.js 88.04% <100.00%> (+0.09%) ⬆️
lib/internal/debugger/inspect_helpers.js 93.14% <100.00%> (+0.61%) ⬆️
lib/internal/debugger/inspect.js 93.29% <62.50%> (-0.71%) ⬇️
lib/internal/debugger/inspect_probe.js 83.76% <76.84%> (+0.79%) ⬆️

... and 61 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Probe mode currently only launches a new process from the entry point
script. This change lets it attach to an already-running process, so a
long-lived application can be inspected without restarting it.

Running `node inspect --probe` without specifying an entry point script
instructs Node.js to attach to a running Node.js process and probe.
The way attaching is done is specified through command line arguments:

- `--pid <pid>` activates the target's inspector (if it's not already
  activated) and connects to it.
- `--host <host>` and `--port <port>` specify an address where an
  inspector is listening. The host defaults to 127.0.0.1 and the
  port defaults to 9229.

When the session ends, probe mode resumes and detaches instead of killing
a process it does not own. The report now includes a top-level `target`
field describing what was probed, and each probe contains a `locations`
field about where it bound.

An attach session ends when a probe reaches `--max-hit`
(reported as `completed`), when the target finishes on its
own (`completed`, or `miss` with the pending probes, and the target is
then allowed to exit), or when `--timeout` fires (reported as `timeout`,
the probing process exit with 0 and reports the hits recorded so far).

`--timeout` now is also applied to the startup phase in both modes, so a
target that never responds before the breakpoints are bound is reported as
an error instead of hanging.

Signed-off-by: Joyee Cheung <joyeec9h3@gmail.com>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

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

Labels

debugger Issues and PRs related to the Node.js command-line debugger. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants