Skip to content

net: expose peer name of pipe connections - #67402

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

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

Conversation

@guybedford

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.

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, and the 'drop' and blockList cases for pipe servers. 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 58.06452% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.73%. Comparing base (e8c1160) to head (ecb7ce1).

Files with missing lines Patch % Lines
src/pipe_wrap.cc 55.55% 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.73%   -0.02%     
==========================================
  Files         798      798              
  Lines      280102   280131      +29     
  Branches    53901    53905       +4     
==========================================
- Hits       254186   254169      -17     
- Misses      16198    16253      +55     
+ Partials     9718     9709       -9     
Files with missing lines Coverage Δ
src/pipe_wrap.h 100.00% <ø> (ø)
lib/net.js 94.88% <75.00%> (+0.09%) ⬆️
src/pipe_wrap.cc 75.46% <55.55%> (-3.96%) ⬇️

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

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++. needs-ci PRs that need a full CI run. net Issues and PRs related to the net subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants