GeezerVison is showing github.com — net: add autoSelectFamily and autoSelectFamilyAttemptTimeout options · nodejs/node@048795d
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: doc/api/net.md +18Lines changed: 18 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -854,6 +854,9 @@ behavior. | 854 | 854 | <!-- YAML | 855 | 855 | added: v0.1.90 | 856 | 856 | changes: | | 857 | + - version: REPLACEME | | 858 | + pr-url: https://github.com/nodejs/node/pull/44731 | | 859 | + description: Added the `autoSelectFamily` option. | 857 | 860 | - version: v17.7.0 | 858 | 861 | pr-url: https://github.com/nodejs/node/pull/41310 | 859 | 862 | description: The `noDelay`, `keepAlive`, and `keepAliveInitialDelay` | @@ -898,6 +901,20 @@ For TCP connections, available `options` are: | 898 | 901 | **Default:** `false`. | 899 | 902 | * `keepAliveInitialDelay` {number} If set to a positive number, it sets the initial delay before | 900 | 903 | the first keepalive probe is sent on an idle socket.**Default:** `0`. | | 904 | +* `autoSelectFamily` {boolean}: If set to `true`, it enables a family autodetection algorithm | | 905 | + that loosely implements section 5 of [RFC 8305][]. | | 906 | + The `all` option passed to lookup is set to `true` and the sockets attempts to connect to all | | 907 | + obtained IPv6 and IPv4 addresses, in sequence, until a connection is established. | | 908 | + The first returned AAAA address is tried first, then the first returned A address and so on. | | 909 | + Each connection attempt is given the amount of time specified by the `autoSelectFamilyAttemptTimeout` | | 910 | + option before timing out and trying the next address. | | 911 | + Ignored if the `family` option is not `0` or if `localAddress` is set. | | 912 | + Connection errors are not emitted if at least one connection succeeds. | | 913 | + **Default:** `false`. | | 914 | +* `autoSelectFamilyAttemptTimeout` {number}: The amount of time in milliseconds to wait | | 915 | + for a connection attempt to finish before trying the next address when using the `autoSelectFamily` option. | | 916 | + If set to a positive integer less than `10`, then the value `10` will be used instead. | | 917 | + **Default:** `250`. | 901 | 918 |
| 902 | 919 | For [IPC][] connections, available `options` are: | 903 | 920 |
| @@ -1622,6 +1639,7 @@ net.isIPv6('fhqwhgads'); // returns false | 1622 | 1639 |
| 1623 | 1640 | [IPC]: #ipc-support | 1624 | 1641 | [Identifying paths for IPC connections]: #identifying-paths-for-ipc-connections | | 1642 | +[RFC 8305]: https://www.rfc-editor.org/rfc/rfc8305.txt | 1625 | 1643 | [Readable Stream]: stream.md#class-streamreadable | 1626 | 1644 | [`'close'`]: #event-close | 1627 | 1645 | [`'connect'`]: #event-connect | |
Collapse file Copy file name to clipboardExpand all lines: lib/_tls_wrap.js +14-4Lines changed: 14 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -54,6 +54,7 @@ const EE = require('events'); | 54 | 54 | const net = require('net'); | 55 | 55 | const tls = require('tls'); | 56 | 56 | const common = require('_tls_common'); | | 57 | +const { kWrapConnectedHandle } = require('internal/net'); | 57 | 58 | const JSStreamSocket = require('internal/js_stream_socket'); | 58 | 59 | const { Buffer } = require('buffer'); | 59 | 60 | let debug = require('internal/util/debuglog').debuglog('tls', (fn) => { | @@ -598,11 +599,10 @@ TLSSocket.prototype.disableRenegotiation = function disableRenegotiation() { | 598 | 599 | this[kDisableRenegotiation] = true; | 599 | 600 | }; | 600 | 601 |
| 601 | | -TLSSocket.prototype._wrapHandle = function(wrap) { | 602 | | - let handle; | 603 | | - | 604 | | - if (wrap) | | 602 | +TLSSocket.prototype._wrapHandle = function(wrap, handle) { | | 603 | + if (!handle && wrap) { | 605 | 604 | handle = wrap._handle; | | 605 | + } | 606 | 606 |
| 607 | 607 | const options = this._tlsOptions; | 608 | 608 | if (!handle) { | @@ -633,6 +633,16 @@ TLSSocket.prototype._wrapHandle = function(wrap) { | 633 | 633 | return res; | 634 | 634 | }; | 635 | 635 |
| | 636 | +TLSSocket.prototype[kWrapConnectedHandle] = function(handle) { | | 637 | + this._handle = this._wrapHandle(null, handle); | | 638 | + this.ssl = this._handle; | | 639 | + this._init(); | | 640 | + | | 641 | + if (this._tlsOptions.enableTrace) { | | 642 | + this._handle.enableTrace(); | | 643 | + } | | 644 | +}; | | 645 | + | 636 | 646 | // This eliminates a cyclic reference to TLSWrap | 637 | 647 | // Ref: https://github.com/nodejs/node/commit/f7620fb96d339f704932f9bb9a0dceb9952df2d4 | 638 | 648 | function defineHandleReading(socket, handle) { | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/errors.js +8Lines changed: 8 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -168,6 +168,13 @@ const aggregateTwoErrors = hideStackFrames((innerError, outerError) => { | 168 | 168 | return innerError || outerError; | 169 | 169 | }); | 170 | 170 |
| | 171 | +const aggregateErrors = hideStackFrames((errors, message, code) => { | | 172 | + // eslint-disable-next-line no-restricted-syntax | | 173 | + const err = new AggregateError(new SafeArrayIterator(errors), message); | | 174 | + err.code = errors[0]?.code; | | 175 | + return err; | | 176 | +}); | | 177 | + | 171 | 178 | // Lazily loaded | 172 | 179 | let util; | 173 | 180 | let assert; | @@ -893,6 +900,7 @@ function determineSpecificType(value) { | 893 | 900 | module.exports = { | 894 | 901 | AbortError, | 895 | 902 | aggregateTwoErrors, | | 903 | + aggregateErrors, | 896 | 904 | captureLargerStackTrace, | 897 | 905 | codes, | 898 | 906 | connResetException, | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/net.js +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -67,6 +67,7 @@ function makeSyncWrite(fd) { | 67 | 67 | } | 68 | 68 |
| 69 | 69 | module.exports = { | | 70 | + kWrapConnectedHandle: Symbol('wrapConnectedHandle'), | 70 | 71 | isIP, | 71 | 72 | isIPv4, | 72 | 73 | isIPv6, | |
|