Skip to content

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

Open
joyeecheung wants to merge 2 commits into
nodejs:mainfrom
joyeecheung:probe-attach-7
Open

joyeecheung wants to merge 2 commits 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.71831% with 72 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.73%. Comparing base (a10b7ec) to head (7960569).
⚠️ Report is 69 commits behind head on main.

Files with missing lines Patch % Lines
lib/internal/debugger/inspect_probe.js 76.92% 64 Missing and 5 partials ⚠️
lib/internal/debugger/inspect.js 62.50% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #67201      +/-   ##
==========================================
+ Coverage   90.67%   90.73%   +0.06%     
==========================================
  Files         797      798       +1     
  Lines      279611   280358     +747     
  Branches    53779    53967     +188     
==========================================
+ Hits       253547   254393     +846     
+ Misses      16351    16249     -102     
- Partials     9713     9716       +3     
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.70% <76.92%> (+0.73%) ⬆️

... and 77 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.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

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

@joyeecheung

Copy link
Copy Markdown
Member Author

CI was green. Would you be interested in reviewing this when you have time? @legendecas @hybrist

Comment thread lib/internal/debugger/inspect_probe.js Resolved
Co-authored-by: Chengzhong Wu <legendecas@gmail.com>
@legendecas legendecas added request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. author ready PRs with CI started, the required approvals, and no outstanding review comments. labels Nov 10, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 10, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@legendecas legendecas added commit-queue PRs queued for automated landing through the Commit Queue. and removed commit-queue PRs queued for automated landing through the Commit Queue. labels Nov 11, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@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

author ready PRs with CI started, the required approvals, and no outstanding review comments. 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.

4 participants