Skip to content

Commit 3d4b956

Browse files
authored
Merge branch 'main' into improve-determine-specific-type
2 parents 77d3a35 + 77597d3 commit 3d4b956

File tree

169 files changed

+4024
-1186
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

169 files changed

+4024
-1186
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,8 @@ maintaining the Node.js project.
721721
**Akhil Marsonya** <<akhil.marsonya27@gmail.com>> (he/him)
722722
* [meixg](https://github.com/meixg) -
723723
**Xuguang Mei** <<meixuguang@gmail.com>> (he/him)
724+
* [mertcanaltin](https://github.com/mertcanaltin) -
725+
**Mert Can Altin** <<mertgold60@gmail.com>>
724726
* [Mesteery](https://github.com/Mesteery) -
725727
**Mestery** <<mestery@protonmail.com>> (he/him)
726728
* [preveen-stack](https://github.com/preveen-stack) -

benchmark/fs/bench-opendirSync.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const fs = require('fs');
5+
const path = require('path');
6+
const tmpdir = require('../../test/common/tmpdir');
7+
tmpdir.refresh();
8+
9+
const testFiles = fs.readdirSync('test', { withFileTypes: true })
10+
.filter((f) => f.isDirectory())
11+
.map((f) => path.join(f.path, f.name));
12+
const bench = common.createBenchmark(main, {
13+
type: ['existing', 'non-existing'],
14+
n: [1e3],
15+
});
16+
17+
function main({ n, type }) {
18+
let files;
19+
20+
switch (type) {
21+
case 'existing':
22+
files = testFiles;
23+
break;
24+
case 'non-existing':
25+
files = [tmpdir.resolve(`.non-existing-file-${Date.now()}`)];
26+
break;
27+
default:
28+
new Error('Invalid type');
29+
}
30+
31+
bench.start();
32+
for (let i = 0; i < n; i++) {
33+
for (let j = 0; j < files.length; j++) {
34+
try {
35+
const dir = fs.opendirSync(files[j]);
36+
dir.closeSync();
37+
} catch {
38+
// do nothing
39+
}
40+
}
41+
}
42+
bench.end(n);
43+
}

benchmark/readline/readline-iterable.js

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const { Readable } = require('stream');
55

66
const bench = common.createBenchmark(main, {
77
n: [1e1, 1e2, 1e3, 1e4, 1e5, 1e6],
8+
type: ['old', 'new'],
89
});
910

1011
const loremIpsum = `Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
@@ -21,6 +22,37 @@ Condimentum mattis pellentesque id nibh tortor id aliquet lectus proin.
2122
Diam in arcu cursus euismod quis viverra nibh.
2223
Rest of line`;
2324

25+
function oldWay() {
26+
const readable = new Readable({
27+
objectMode: true,
28+
read: () => {
29+
this.resume();
30+
},
31+
destroy: (err, cb) => {
32+
this.off('line', lineListener);
33+
this.off('close', closeListener);
34+
this.close();
35+
cb(err);
36+
},
37+
});
38+
const lineListener = (input) => {
39+
if (!readable.push(input)) {
40+
// TODO(rexagod): drain to resume flow
41+
this.pause();
42+
}
43+
};
44+
const closeListener = () => {
45+
readable.push(null);
46+
};
47+
const errorListener = (err) => {
48+
readable.destroy(err);
49+
};
50+
this.on('error', errorListener);
51+
this.on('line', lineListener);
52+
this.on('close', closeListener);
53+
return readable[Symbol.asyncIterator]();
54+
}
55+
2456
function getLoremIpsumStream(repetitions) {
2557
const readable = Readable({
2658
objectMode: true,
@@ -32,16 +64,18 @@ function getLoremIpsumStream(repetitions) {
3264
return readable;
3365
}
3466

35-
async function main({ n }) {
67+
async function main({ n, type }) {
3668
bench.start();
3769
let lineCount = 0;
3870

3971
const iterable = readline.createInterface({
4072
input: getLoremIpsumStream(n),
4173
});
4274

75+
const readlineIterable = type === 'old' ? oldWay.call(iterable) : iterable;
76+
4377
// eslint-disable-next-line no-unused-vars
44-
for await (const _ of iterable) {
78+
for await (const _ of readlineIterable) {
4579
lineCount++;
4680
}
4781
bench.end(lineCount);

deps/googletest/src/gtest-port.cc

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,13 @@ size_t GetThreadCount() {
158158
// we cannot detect it.
159159
size_t GetThreadCount() {
160160
int mib[] = {
161-
CTL_KERN,
162-
KERN_PROC,
163-
KERN_PROC_PID,
164-
getpid(),
161+
CTL_KERN,
162+
KERN_PROC,
163+
KERN_PROC_PID,
164+
getpid(),
165165
#ifdef GTEST_OS_NETBSD
166-
sizeof(struct kinfo_proc),
167-
1,
166+
sizeof(struct kinfo_proc),
167+
1,
168168
#endif
169169
};
170170
u_int miblen = sizeof(mib) / sizeof(mib[0]);
@@ -1028,6 +1028,16 @@ GTEST_DISABLE_MSC_DEPRECATED_PUSH_()
10281028

10291029
#if GTEST_HAS_STREAM_REDIRECTION
10301030

1031+
namespace {
1032+
1033+
#if defined(GTEST_OS_LINUX_ANDROID) || defined(GTEST_OS_IOS)
1034+
bool EndsWithPathSeparator(const std::string& path) {
1035+
return !path.empty() && path.back() == GTEST_PATH_SEP_[0];
1036+
}
1037+
#endif
1038+
1039+
} // namespace
1040+
10311041
// Object that captures an output stream (stdout/stderr).
10321042
class CapturedStream {
10331043
public:
@@ -1064,7 +1074,13 @@ class CapturedStream {
10641074
// The location /data/local/tmp is directly accessible from native code.
10651075
// '/sdcard' and other variants cannot be relied on, as they are not
10661076
// guaranteed to be mounted, or may have a delay in mounting.
1067-
name_template = "/data/local/tmp/";
1077+
//
1078+
// However, prefer using the TMPDIR environment variable if set, as newer
1079+
// devices may have /data/local/tmp read-only.
1080+
name_template = TempDir();
1081+
if (!EndsWithPathSeparator(name_template))
1082+
name_template.push_back(GTEST_PATH_SEP_[0]);
1083+
10681084
#elif defined(GTEST_OS_IOS)
10691085
char user_temp_dir[PATH_MAX + 1];
10701086

@@ -1084,7 +1100,7 @@ class CapturedStream {
10841100
::confstr(_CS_DARWIN_USER_TEMP_DIR, user_temp_dir, sizeof(user_temp_dir));
10851101

10861102
name_template = user_temp_dir;
1087-
if (name_template.back() != GTEST_PATH_SEP_[0])
1103+
if (!EndsWithPathSeparator(name_template))
10881104
name_template.push_back(GTEST_PATH_SEP_[0]);
10891105
#else
10901106
name_template = "/tmp/";

deps/undici/src/README.md

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,34 @@ npm i undici
1818
## Benchmarks
1919

2020
The benchmark is a simple `hello world` [example](benchmarks/benchmark.js) using a
21-
number of unix sockets (connections) with a pipelining depth of 10 running on Node 16.
22-
The benchmarks below have the [simd](https://github.com/WebAssembly/simd) feature enabled.
21+
number of unix sockets (connections) with a pipelining depth of 10 running on Node 20.6.0.
2322

2423
### Connections 1
2524

25+
2626
| Tests | Samples | Result | Tolerance | Difference with slowest |
2727
|---------------------|---------|---------------|-----------|-------------------------|
28-
| http - no keepalive | 15 | 4.63 req/sec | ± 2.77 % | - |
29-
| http - keepalive | 10 | 4.81 req/sec | ± 2.16 % | + 3.94 % |
30-
| undici - stream | 25 | 62.22 req/sec | ± 2.67 % | + 1244.58 % |
31-
| undici - dispatch | 15 | 64.33 req/sec | ± 2.47 % | + 1290.24 % |
32-
| undici - request | 15 | 66.08 req/sec | ± 2.48 % | + 1327.88 % |
33-
| undici - pipeline | 10 | 66.13 req/sec | ± 1.39 % | + 1329.08 % |
28+
| http - no keepalive | 15 | 5.32 req/sec | ± 2.61 % | - |
29+
| http - keepalive | 10 | 5.35 req/sec | ± 2.47 % | + 0.44 % |
30+
| undici - fetch | 15 | 41.85 req/sec | ± 2.49 % | + 686.04 % |
31+
| undici - pipeline | 40 | 50.36 req/sec | ± 2.77 % | + 845.92 % |
32+
| undici - stream | 15 | 60.58 req/sec | ± 2.75 % | + 1037.72 % |
33+
| undici - request | 10 | 61.19 req/sec | ± 2.60 % | + 1049.24 % |
34+
| undici - dispatch | 20 | 64.84 req/sec | ± 2.81 % | + 1117.81 % |
35+
3436

3537
### Connections 50
3638

3739
| Tests | Samples | Result | Tolerance | Difference with slowest |
3840
|---------------------|---------|------------------|-----------|-------------------------|
39-
| http - no keepalive | 50 | 3546.49 req/sec | ± 2.90 % | - |
40-
| http - keepalive | 15 | 5692.67 req/sec | ± 2.48 % | + 60.52 % |
41-
| undici - pipeline | 25 | 8478.71 req/sec | ± 2.62 % | + 139.07 % |
42-
| undici - request | 20 | 9766.66 req/sec | ± 2.79 % | + 175.39 % |
43-
| undici - stream | 15 | 10109.74 req/sec | ± 2.94 % | + 185.06 % |
44-
| undici - dispatch | 25 | 10949.73 req/sec | ± 2.54 % | + 208.75 % |
41+
| undici - fetch | 30 | 2107.19 req/sec | ± 2.69 % | - |
42+
| http - no keepalive | 10 | 2698.90 req/sec | ± 2.68 % | + 28.08 % |
43+
| http - keepalive | 10 | 4639.49 req/sec | ± 2.55 % | + 120.17 % |
44+
| undici - pipeline | 40 | 6123.33 req/sec | ± 2.97 % | + 190.59 % |
45+
| undici - stream | 50 | 9426.51 req/sec | ± 2.92 % | + 347.35 % |
46+
| undici - request | 10 | 10162.88 req/sec | ± 2.13 % | + 382.29 % |
47+
| undici - dispatch | 50 | 11191.11 req/sec | ± 2.98 % | + 431.09 % |
48+
4549

4650
## Quick Start
4751

@@ -432,6 +436,7 @@ and `undici.Agent`) which will enable the family autoselection algorithm when es
432436
* [__Ethan Arrowood__](https://github.com/ethan-arrowood), <https://www.npmjs.com/~ethan_arrowood>
433437
* [__Matteo Collina__](https://github.com/mcollina), <https://www.npmjs.com/~matteo.collina>
434438
* [__Robert Nagy__](https://github.com/ronag), <https://www.npmjs.com/~ronag>
439+
* [__Matthew Aitken__](https://github.com/KhafraDev), <https://www.npmjs.com/~khaf>
435440

436441
## License
437442

deps/undici/src/docs/api/Client.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ Returns: `Client`
1717

1818
### Parameter: `ClientOptions`
1919

20+
> ⚠️ Warning: The `H2` support is experimental.
21+
2022
* **bodyTimeout** `number | null` (optional) - Default: `300e3` - The timeout after which a request will time out, in milliseconds. Monitors time between receiving body data. Use `0` to disable it entirely. Defaults to 300 seconds.
21-
* **headersTimeout** `number | null` (optional) - Default: `300e3` - The amount of time the parser will wait to receive the complete HTTP headers while not sending the request. Defaults to 300 seconds.
22-
* **keepAliveMaxTimeout** `number | null` (optional) - Default: `600e3` - The maximum allowed `keepAliveTimeout` when overridden by *keep-alive* hints from the server. Defaults to 10 minutes.
23-
* **keepAliveTimeout** `number | null` (optional) - Default: `4e3` - The timeout after which a socket without active requests will time out. Monitors time between activity on a connected socket. This value may be overridden by *keep-alive* hints from the server. See [MDN: HTTP - Headers - Keep-Alive directives](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Keep-Alive#directives) for more details. Defaults to 4 seconds.
24-
* **keepAliveTimeoutThreshold** `number | null` (optional) - Default: `1e3` - A number subtracted from server *keep-alive* hints when overriding `keepAliveTimeout` to account for timing inaccuracies caused by e.g. transport latency. Defaults to 1 second.
23+
* **headersTimeout** `number | null` (optional) - Default: `300e3` - The amount of time, in milliseconds, the parser will wait to receive the complete HTTP headers while not sending the request. Defaults to 300 seconds.
24+
* **keepAliveMaxTimeout** `number | null` (optional) - Default: `600e3` - The maximum allowed `keepAliveTimeout`, in milliseconds, when overridden by *keep-alive* hints from the server. Defaults to 10 minutes.
25+
* **keepAliveTimeout** `number | null` (optional) - Default: `4e3` - The timeout, in milliseconds, after which a socket without active requests will time out. Monitors time between activity on a connected socket. This value may be overridden by *keep-alive* hints from the server. See [MDN: HTTP - Headers - Keep-Alive directives](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Keep-Alive#directives) for more details. Defaults to 4 seconds.
26+
* **keepAliveTimeoutThreshold** `number | null` (optional) - Default: `1e3` - A number of milliseconds subtracted from server *keep-alive* hints when overriding `keepAliveTimeout` to account for timing inaccuracies caused by e.g. transport latency. Defaults to 1 second.
2527
* **maxHeaderSize** `number | null` (optional) - Default: `16384` - The maximum length of request headers in bytes. Defaults to 16KiB.
2628
* **maxResponseSize** `number | null` (optional) - Default: `-1` - The maximum length of response body in bytes. Set to `-1` to disable.
2729
* **pipelining** `number | null` (optional) - Default: `1` - The amount of concurrent requests to be sent over the single TCP/TLS connection according to [RFC7230](https://tools.ietf.org/html/rfc7230#section-6.3.2). Carefully consider your workload and environment before enabling concurrent requests as pipelining may reduce performance if used incorrectly. Pipelining is sensitive to network stack settings as well as head of line blocking caused by e.g. long running requests. Set to `0` to disable keep-alive connections.
@@ -30,6 +32,8 @@ Returns: `Client`
3032
* **interceptors** `{ Client: DispatchInterceptor[] }` - Default: `[RedirectInterceptor]` - A list of interceptors that are applied to the dispatch method. Additional logic can be applied (such as, but not limited to: 302 status code handling, authentication, cookies, compression and caching). Note that the behavior of interceptors is Experimental and might change at any given time.
3133
* **autoSelectFamily**: `boolean` (optional) - Default: depends on local Node version, on Node 18.13.0 and above is `false`. Enables a family autodetection algorithm that loosely implements section 5 of [RFC 8305](https://tools.ietf.org/html/rfc8305#section-5). See [here](https://nodejs.org/api/net.html#socketconnectoptions-connectlistener) for more details. This option is ignored if not supported by the current Node version.
3234
* **autoSelectFamilyAttemptTimeout**: `number` - Default: depends on local Node version, on Node 18.13.0 and above is `250`. The amount of time in milliseconds to wait for a connection attempt to finish before trying the next address when using the `autoSelectFamily` option. See [here](https://nodejs.org/api/net.html#socketconnectoptions-connectlistener) for more details.
35+
* **allowH2**: `boolean` - Default: `false`. Enables support for H2 if the server has assigned bigger priority to it through ALPN negotiation.
36+
* **maxConcurrentStreams**: `number` - Default: `100`. Dictates the maximum number of concurrent streams for a single H2 session. It can be overriden by a SETTINGS remote frame.
3337

3438
#### Parameter: `ConnectOptions`
3539

@@ -38,7 +42,7 @@ Furthermore, the following options can be passed:
3842

3943
* **socketPath** `string | null` (optional) - Default: `null` - An IPC endpoint, either Unix domain socket or Windows named pipe.
4044
* **maxCachedSessions** `number | null` (optional) - Default: `100` - Maximum number of TLS cached sessions. Use 0 to disable TLS session caching. Default: 100.
41-
* **timeout** `number | null` (optional) - Default `10e3`
45+
* **timeout** `number | null` (optional) - In milliseconds, Default `10e3`.
4246
* **servername** `string | null` (optional)
4347
* **keepAlive** `boolean | null` (optional) - Default: `true` - TCP keep-alive enabled
4448
* **keepAliveInitialDelay** `number | null` (optional) - Default: `60000` - TCP keep-alive interval for the socket in milliseconds

deps/undici/src/docs/api/Connector.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ Every Tls option, see [here](https://nodejs.org/api/tls.html#tls_tls_connect_opt
1313
Furthermore, the following options can be passed:
1414

1515
* **socketPath** `string | null` (optional) - Default: `null` - An IPC endpoint, either Unix domain socket or Windows named pipe.
16-
* **maxCachedSessions** `number | null` (optional) - Default: `100` - Maximum number of TLS cached sessions. Use 0 to disable TLS session caching. Default: 100.
17-
* **timeout** `number | null` (optional) - Default `10e3`
16+
* **maxCachedSessions** `number | null` (optional) - Default: `100` - Maximum number of TLS cached sessions. Use 0 to disable TLS session caching. Default: `100`.
17+
* **timeout** `number | null` (optional) - In milliseconds. Default `10e3`.
1818
* **servername** `string | null` (optional)
1919

2020
Once you call `buildConnector`, it will return a connector function, which takes the following parameters.

deps/undici/src/docs/api/Dispatcher.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,9 @@ Returns: `Boolean` - `false` if dispatcher is busy and further dispatch calls wo
200200
* **blocking** `boolean` (optional) - Default: `false` - Whether the response is expected to take a long time and would end up blocking the pipeline. When this is set to `true` further pipelining will be avoided on the same connection until headers have been received.
201201
* **upgrade** `string | null` (optional) - Default: `null` - Upgrade the request. Should be used to specify the kind of upgrade i.e. `'Websocket'`.
202202
* **bodyTimeout** `number | null` (optional) - The timeout after which a request will time out, in milliseconds. Monitors time between receiving body data. Use `0` to disable it entirely. Defaults to 300 seconds.
203-
* **headersTimeout** `number | null` (optional) - The amount of time the parser will wait to receive the complete HTTP headers while not sending the request. Defaults to 300 seconds.
203+
* **headersTimeout** `number | null` (optional) - The amount of time, in milliseconds, the parser will wait to receive the complete HTTP headers while not sending the request. Defaults to 300 seconds.
204204
* **throwOnError** `boolean` (optional) - Default: `false` - Whether Undici should throw an error upon receiving a 4xx or 5xx response from the server.
205+
* **expectContinue** `boolean` (optional) - Default: `false` - For H2, it appends the expect: 100-continue header, and halts the request body until a 100-continue is received from the remote server
205206

206207
#### Parameter: `DispatchHandler`
207208

deps/undici/src/docs/api/MockPool.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ const mockPool = mockAgent.get('http://localhost:3000')
3535

3636
### `MockPool.intercept(options)`
3737

38-
This method defines the interception rules for matching against requests for a MockPool or MockPool. We can intercept multiple times on a single instance.
38+
This method defines the interception rules for matching against requests for a MockPool or MockPool. We can intercept multiple times on a single instance, but each intercept is only used once.
39+
For example if you expect to make 2 requests inside a test, you need to call `intercept()` twice. Assuming you use `disableNetConnect()` you will get `MockNotMatchedError` on the second request when you only call `intercept()` once.
3940

4041
When defining interception rules, all the rules must pass for a request to be intercepted. If a request is not intercepted, a real request will be attempted.
4142

deps/undici/src/index-fetch.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
const fetchImpl = require('./lib/fetch').fetch
44

5-
module.exports.fetch = async function fetch (resource) {
5+
module.exports.fetch = async function fetch (resource, init = undefined) {
66
try {
7-
return await fetchImpl(...arguments)
7+
return await fetchImpl(resource, init)
88
} catch (err) {
99
Error.captureStackTrace(err, this)
1010
throw err
@@ -14,3 +14,4 @@ module.exports.FormData = require('./lib/fetch/formdata').FormData
1414
module.exports.Headers = require('./lib/fetch/headers').Headers
1515
module.exports.Response = require('./lib/fetch/response').Response
1616
module.exports.Request = require('./lib/fetch/request').Request
17+
module.exports.WebSocket = require('./lib/websocket/websocket').WebSocket

0 commit comments

Comments
 (0)