Skip to content

Commit 686952c

Browse files
committed
pr feedback
1 parent cc60766 commit 686952c

3 files changed

Lines changed: 47 additions & 8 deletions

File tree

‎doc/api/net.md‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,10 +1717,6 @@ throw [`ERR_SOCKET_HANDLE_ADOPTED`][]. A handle that is never adopted must be
17171717
closed to avoid leaking the socket. Closing a pipe `BoundSocket` removes its
17181718
file system entry; abstract and TCP binds have none to remove.
17191719

1720-
The presence of the [`boundSocket.isPipe`][] getter on
1721-
`net.BoundSocket.prototype` is a capability signal that a build honors the
1722-
`path` option rather than silently binding a TCP ephemeral port.
1723-
17241720
When a pipe `BoundSocket` bound to a source `path` is adopted as a client, that
17251721
path is reported as the socket's `localAddress` once it connects.
17261722

@@ -1744,6 +1740,10 @@ server.listen(bound); // Adopt as a server, or pass to new net.Socket() instead.
17441740

17451741
<!-- YAML
17461742
added: v26.4.0
1743+
changes:
1744+
- version: REPLACEME
1745+
pr-url: https://github.com/nodejs/node/pull/64399
1746+
description: The `path` option is supported.
17471747
-->
17481748

17491749
* `options` {Object}
@@ -1767,6 +1767,10 @@ added: v26.4.0
17671767

17681768
<!-- YAML
17691769
added: v26.4.0
1770+
changes:
1771+
- version: REPLACEME
1772+
pr-url: https://github.com/nodejs/node/pull/64399
1773+
description: The bound path is returned for a pipe bind.
17701774
-->
17711775

17721776
* Returns: {Object|string} For a TCP bind, an object with `address`, `family`,
@@ -2298,7 +2302,6 @@ net.isIPv6('fhqwhgads'); // returns false
22982302
[`ERR_INVALID_ARG_VALUE`]: errors.md#err_invalid_arg_value
22992303
[`ERR_SOCKET_HANDLE_ADOPTED`]: errors.md#err_socket_handle_adopted
23002304
[`EventEmitter`]: events.md#class-eventemitter
2301-
[`boundSocket.isPipe`]: #boundsocketispipe
23022305
[`child_process.fork()`]: child_process.md#child_processforkmodulepath-args-options
23032306
[`dns.lookup()`]: dns.md#dnslookuphostname-options-callback
23042307
[`dns.lookup()` hints]: dns.md#supported-getaddrinfo-flags

‎lib/net.js‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,9 +1557,11 @@ Socket.prototype.connect = function(...args) {
15571557
const { path } = options;
15581558
// An adopted BoundSocket handle already fixes the transport; trust its type
15591559
// rather than inferring pipe-ness from a path option on the connect call.
1560-
// Other pre-existing handles (e.g. a TLSWrap) are not transport handles, so
1561-
// fall back to the path option in that case.
1562-
const pipe = this[kBoundSource] ? this._handle instanceof Pipe : !!path;
1560+
// Once destroyed the adopted handle is gone (its reservation released), so
1561+
// fall back to the path option, as for other pre-existing handles (e.g. a
1562+
// TLSWrap) that are not transport handles.
1563+
const pipe = this[kBoundSource] && this._handle ?
1564+
this._handle instanceof Pipe : !!path;
15631565
debug('pipe', pipe, path);
15641566

15651567
if (!this._handle) {

‎test/parallel/test-net-boundsocket.js‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,40 @@ if (!common.isWindows) {
341341
}));
342342
}
343343

344+
// Reconnecting an adopted pipe BoundSocket after destroy: the adopted handle is
345+
// gone, so pipe-ness must come from the path option rather than the (now null)
346+
// handle, otherwise connect() would wrongly attempt a TCP connect.
347+
if (!common.isWindows) {
348+
const path = `${common.PIPE}-reconnect`;
349+
350+
const server = net.createServer(common.mustCall((socket) => {
351+
socket.on('data', (data) => socket.end(data));
352+
}, 2));
353+
354+
const bound = new net.BoundSocket({ path: `${path}-src` });
355+
server.listen(path, common.mustCall(() => {
356+
const client = new net.Socket({ handle: bound });
357+
client.connect({ path });
358+
client.once('connect', common.mustCall(() => {
359+
client.end('ping');
360+
client.once('data', common.mustCall((data) => {
361+
assert.strictEqual(data.toString(), 'ping');
362+
}));
363+
client.once('close', common.mustCall(() => {
364+
// The adopted handle is gone; reconnect must still be a pipe.
365+
client.connect({ path });
366+
client.once('connect', common.mustCall(() => {
367+
client.end('pong');
368+
client.once('data', common.mustCall((data) => {
369+
assert.strictEqual(data.toString(), 'pong');
370+
}));
371+
client.once('close', common.mustCall(() => server.close()));
372+
}));
373+
}));
374+
}));
375+
}));
376+
}
377+
344378
// Linux abstract namespace: a leading '\0' binds without creating a filesystem
345379
// entry, and still listens/connects.
346380
if (isLinux) {

0 commit comments

Comments
 (0)