Skip to content

net: expose peer name of pipe connections - #67402

Open
guybedford wants to merge 4 commits into
nodejs:mainfrom
guybedford:net-pipe-remote-address
Open

guybedford wants to merge 4 commits into
nodejs:mainfrom
guybedford:net-pipe-remote-address

Conversation

@guybedford

@guybedford guybedford commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

This exposes the peer name of Unix domain socket connections as socket.remoteAddress.

getpeername(2) on a Unix domain socket returns the path the peer is bound to, but the pipe handle had no getpeername method, so socket.remoteAddress was always undefined for pipe connections, even when the client was bound to a path through net.BoundSocket({ path }).

const server = net.createServer((socket) => {
  socket.remoteAddress; // previously undefined, now clientPath
});
server.listen(serverPath, () => {
  const client = new net.Socket({
    handle: new net.BoundSocket({ path: clientPath }),
  });
  client.connect({ path: serverPath }, () => {
    client.remoteAddress; // previously undefined, now serverPath
  });
});
  • The pipe handle gains getpeername, backed by uv_pipe_getpeername().
  • remoteAddress stays undefined when the peer is not bound to a path, which is the case for most clients.
  • remoteFamily and remotePort stay undefined for pipes, matching localFamily and localPort.
  • Linux abstract socket names are reported with their leading NUL byte.
  • On Windows remoteAddress stays undefined, since a named pipe has a single name rather than one per end.
  • The server 'drop' data and blockList check keyed off the accepted handle having getpeername, so both are now restricted to non-pipe handles. Without this a blockList on a pipe server would reject every connection, and 'drop' would stop passing undefined for pipes as documented.
  • http2 used remoteAddress as the origin host for a TLS socket without a servername, so a pipe's peer path would be parsed as a host, throwing ERR_INVALID_URL for an abstract name. session.originSet now uses https://localhost when the socket has no remote family, where it previously reported https://undefined.

Tests cover bound and unbound clients, the connecting side, abstract names, reading the cached value after the peer has closed and the socket is destroyed, the 'drop' and blockList cases for pipe servers, and the http2 origin set for TLS over a pipe without a servername. TCP behavior is unchanged.

getpeername(2) on a Unix domain socket returns the path the peer is
bound to, but the pipe handle had no getpeername method, so
socket.remoteAddress was always undefined for pipe connections.

Add getpeername to the pipe handle, backed by uv_pipe_getpeername(), so
that socket.remoteAddress reports the listening path on the connecting
side and the path of a bound client on the accepting side. It remains
undefined for an unbound peer, and on Windows, where a named pipe has a
single name rather than one per end.

The server 'drop' data and BlockList check keyed off the presence of
getpeername on the accepted handle, so restrict both to non-pipe
handles to keep their behavior for pipe servers unchanged.

Signed-off-by: Guy Bedford <guybedford@gmail.com>
Assisted-by: Claude Fable 5.2
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/net

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. net Issues and PRs related to the net subsystem. labels Nov 11, 2026
Signed-off-by: Guy Bedford <guybedford@gmail.com>
Assisted-by: Claude Fable 5.2
@codecov

codecov Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 61.76471% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.71%. Comparing base (e8c1160) to head (dff1634).
⚠️ Report is 206 commits behind head on main.

Files with missing lines Patch % Lines
src/pipe_wrap.cc 53.84% 5 Missing and 7 partials ⚠️
lib/net.js 75.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #67402      +/-   ##
==========================================
- Coverage   90.74%   90.71%   -0.04%     
==========================================
  Files         798      801       +3     
  Lines      280102   280817     +715     
  Branches    53901    54212     +311     
==========================================
+ Hits       254186   254734     +548     
- Misses      16198    16246      +48     
- Partials     9718     9837     +119     
Files with missing lines Coverage Δ
lib/internal/http2/core.js 95.00% <100.00%> (+0.07%) ⬆️
src/pipe_wrap.h 100.00% <ø> (ø)
lib/net.js 94.88% <75.00%> (+0.09%) ⬆️
src/pipe_wrap.cc 75.30% <53.84%> (-4.11%) ⬇️

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

@Ethan-Arrowood Ethan-Arrowood left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This LGTM. Need to run the C++ linter though.

My agent claims this change is currently causing a crash for "http2 client over TLS on a Linux abstract socket" because initOriginSet falls back to socket.remoteAdress when there is no servername. This causes an ERR_INVALID_URL on this branch, but currently works fine on main. It suggest using remoteAddress only when remoteFamily is set. I checked its work, and am confident in the analysis, but since its pretty far out of my core understanding, I'll leave it to you to independently verify and consider what is the most appropriate change.

I'm personally fine with this landing as is as long as it passes CI of course.

Great work!

AI-assisted (Claude Opus 5.5, my setup). The words are my own, per the Human Voice policy.

@Ethan-Arrowood Ethan-Arrowood added the semver-minor PRs that contain new features and should be released in the next minor version. label Nov 17, 2026
@jasnell jasnell added 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 18, 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 18, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Keep the http2 origin set from using a pipe's peer path as a host name,
and apply clang-format.

Signed-off-by: Guy Bedford <guybedford@gmail.com>
Assisted-by: Claude Fable 5.2
Use localhost as the http2 origin host for a pipe without a servername.

Signed-off-by: Guy Bedford <guybedford@gmail.com>
Assisted-by: Claude Fable 5.2
@guybedford

Copy link
Copy Markdown
Contributor Author

Thanks @Ethan-Arrowood for the review. Both points were correct - when remoteAddress is undefined, h2.connect against a path will reflect https://undefined. I've updated this case so that pipe paths always reflect https://localhost instead. While https://undefined is the behavior on main, improving that seems worthwhile to me.

@Ethan-Arrowood Ethan-Arrowood left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

excellent. lgtm!

@Ethan-Arrowood Ethan-Arrowood added request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. commit-queue-squash PRs the Commit Queue should land as one squashed commit. labels Nov 19, 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 19, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@Ethan-Arrowood Ethan-Arrowood added the commit-queue PRs queued for automated landing through the Commit Queue. label Nov 20, 2026
@nodejs-github-bot nodejs-github-bot added commit-queue-failed PRs whose Commit Queue landing failed and need manual intervention before retrying. and removed commit-queue PRs queued for automated landing through the Commit Queue. labels Nov 20, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Commit Queue failed

   ⚠  Could not retrieve the email or name of the PR's author from user's GitHub profile!
   ✖  GitHub CI is still running

The pull request was removed from the Commit Queue and labeled commit-queue-failed PRs whose Commit Queue landing failed and need manual intervention before retrying. . After resolving the failure, remove that label and add commit-queue PRs queued for automated landing through the Commit Queue. to retry.

Full Commit Queue output
�[36m⠋�[39m Loading data for nodejs/node/pull/67402
�[36m⠋�[39m Loading data for nodejs/node/pull/67402
�[36m⠋�[39m Getting collaborator contacts from README of nodejs/node
�[36m⠋�[39m Getting PR from nodejs/node/pull/67402
�[36m⠋�[39m Getting reviews from nodejs/node/pull/67402
�[36m⠋�[39m Getting comments from nodejs/node/pull/67402
�[36m⠋�[39m Getting commits from nodejs/node/pull/67402
✔  Done loading data for nodejs/node/pull/67402
----------------------------------- PR info ------------------------------------
Title      net: expose peer name of pipe connections (#67402)
   ⚠  Could not retrieve the email or name of the PR's author from user's GitHub profile!
Branch     guybedford:net-pipe-remote-address -> nodejs:main
Labels     c++, net, semver-minor, needs-ci, commit-queue, commit-queue-squash
Commits    4
 - net: expose peer name of pipe connections
 - fixup! net: expose peer name of pipe connections
 - fixup! net: expose peer name of pipe connections
 - fixup! net: expose peer name of pipe connections
Committers 2
 - Guy Bedford <gbedford@cloudflare.com>
 - Guy Bedford <guybedford@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/67402
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
Reviewed-By: James M Snell <jasnell@gmail.com>
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/67402
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
Reviewed-By: James M Snell <jasnell@gmail.com>
--------------------------------------------------------------------------------
   ℹ  This PR was created on Wed, 11 Nov 2026 05:05:38 GMT
   ✔  Approvals: 2
   ✔  - Ethan Arrowood (@Ethan-Arrowood): https://github.com/nodejs/node/pull/67402#pullrequestreview-5980599723
   ✔  - James M Snell (@jasnell) (TSC): https://github.com/nodejs/node/pull/67402#pullrequestreview-5956686969
   ✖  GitHub CI is still running
   ℹ  Last Full PR CI on 2026-11-19T18:09:36Z: https://ci.nodejs.org/job/node-test-pull-request/79309/
�[36m⠙�[39m Querying data for job/node-test-pull-request/79309/
�[36m⠙�[39m Querying data for job/node-test-pull-request/79309/
�[36m⠙�[39m Querying API for job/node-test-pull-request/79309/
✔  Build data downloaded
   ✔  Last Jenkins CI successful
--------------------------------------------------------------------------------
   ✔  Aborted `git node land` session in /home/runner/work/node/node/.ncu

View workflow run

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

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. commit-queue-failed PRs whose Commit Queue landing failed and need manual intervention before retrying. commit-queue-squash PRs the Commit Queue should land as one squashed commit. needs-ci PRs that need a full CI run. net Issues and PRs related to the net subsystem. semver-minor PRs that contain new features and should be released in the next minor version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants