Skip to content

Commit 61d18d6

Browse files
nodejs-github-botruyadorno
authored andcommitted
deps: update undici to 5.24.0
PR-URL: #49559 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Matthew Aitken <maitken033380023@gmail.com>
1 parent efd6815 commit 61d18d6

33 files changed

+2679
-311
lines changed

deps/undici/src/README.md

+19-14
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

+9-5
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

+2-2
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

+2-1
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

+2-1
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

+3-2
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

deps/undici/src/index.d.ts

+2-56
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,3 @@
1-
import Dispatcher from'./types/dispatcher'
2-
import { setGlobalDispatcher, getGlobalDispatcher } from './types/global-dispatcher'
3-
import { setGlobalOrigin, getGlobalOrigin } from './types/global-origin'
4-
import Pool from'./types/pool'
5-
import { RedirectHandler, DecoratorHandler } from './types/handlers'
6-
7-
import BalancedPool from './types/balanced-pool'
8-
import Client from'./types/client'
9-
import buildConnector from'./types/connector'
10-
import errors from'./types/errors'
11-
import Agent from'./types/agent'
12-
import MockClient from'./types/mock-client'
13-
import MockPool from'./types/mock-pool'
14-
import MockAgent from'./types/mock-agent'
15-
import mockErrors from'./types/mock-errors'
16-
import ProxyAgent from'./types/proxy-agent'
17-
import { request, pipeline, stream, connect, upgrade } from './types/api'
18-
19-
export * from './types/cookies'
20-
export * from './types/fetch'
21-
export * from './types/file'
22-
export * from './types/filereader'
23-
export * from './types/formdata'
24-
export * from './types/diagnostics-channel'
25-
export * from './types/websocket'
26-
export * from './types/content-type'
27-
export * from './types/cache'
28-
export { Interceptable } from './types/mock-interceptor'
29-
30-
export { Dispatcher, BalancedPool, Pool, Client, buildConnector, errors, Agent, request, stream, pipeline, connect, upgrade, setGlobalDispatcher, getGlobalDispatcher, setGlobalOrigin, getGlobalOrigin, MockClient, MockPool, MockAgent, mockErrors, ProxyAgent, RedirectHandler, DecoratorHandler }
1+
export * from './types/index'
2+
import Undici from './types/index'
313
export default Undici
32-
33-
declare namespace Undici {
34-
var Dispatcher: typeof import('./types/dispatcher').default
35-
var Pool: typeof import('./types/pool').default;
36-
var RedirectHandler: typeof import ('./types/handlers').RedirectHandler
37-
var DecoratorHandler: typeof import ('./types/handlers').DecoratorHandler
38-
var createRedirectInterceptor: typeof import ('./types/interceptors').createRedirectInterceptor
39-
var BalancedPool: typeof import('./types/balanced-pool').default;
40-
var Client: typeof import('./types/client').default;
41-
var buildConnector: typeof import('./types/connector').default;
42-
var errors: typeof import('./types/errors').default;
43-
var Agent: typeof import('./types/agent').default;
44-
var setGlobalDispatcher: typeof import('./types/global-dispatcher').setGlobalDispatcher;
45-
var getGlobalDispatcher: typeof import('./types/global-dispatcher').getGlobalDispatcher;
46-
var request: typeof import('./types/api').request;
47-
var stream: typeof import('./types/api').stream;
48-
var pipeline: typeof import('./types/api').pipeline;
49-
var connect: typeof import('./types/api').connect;
50-
var upgrade: typeof import('./types/api').upgrade;
51-
var MockClient: typeof import('./types/mock-client').default;
52-
var MockPool: typeof import('./types/mock-pool').default;
53-
var MockAgent: typeof import('./types/mock-agent').default;
54-
var mockErrors: typeof import('./types/mock-errors').default;
55-
var fetch: typeof import('./types/fetch').fetch;
56-
var caches: typeof import('./types/cache').caches;
57-
}

deps/undici/src/index.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,10 @@ if (util.nodeMajor > 16 || (util.nodeMajor === 16 && util.nodeMinor >= 8)) {
106106
try {
107107
return await fetchImpl(...arguments)
108108
} catch (err) {
109-
Error.captureStackTrace(err, this)
109+
if (typeof err === 'object') {
110+
Error.captureStackTrace(err, this)
111+
}
112+
110113
throw err
111114
}
112115
}

deps/undici/src/lib/api/api-connect.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict'
22

3-
const { InvalidArgumentError, RequestAbortedError, SocketError } = require('../core/errors')
43
const { AsyncResource } = require('async_hooks')
4+
const { InvalidArgumentError, RequestAbortedError, SocketError } = require('../core/errors')
55
const util = require('../core/util')
66
const { addSignal, removeSignal } = require('./abort-signal')
77

@@ -50,7 +50,13 @@ class ConnectHandler extends AsyncResource {
5050
removeSignal(this)
5151

5252
this.callback = null
53-
const headers = this.responseHeaders === 'raw' ? util.parseRawHeaders(rawHeaders) : util.parseHeaders(rawHeaders)
53+
54+
let headers = rawHeaders
55+
// Indicates is an HTTP2Session
56+
if (headers != null) {
57+
headers = this.responseHeaders === 'raw' ? util.parseRawHeaders(rawHeaders) : util.parseHeaders(rawHeaders)
58+
}
59+
5460
this.runInAsyncScope(callback, null, null, {
5561
statusCode,
5662
headers,

deps/undici/src/lib/api/api-request.js

-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ class RequestHandler extends AsyncResource {
9595

9696
this.callback = null
9797
this.res = body
98-
9998
if (callback !== null) {
10099
if (this.throwOnError && statusCode >= 400) {
101100
this.runInAsyncScope(getResolveErrorBodyCallback, null,

deps/undici/src/lib/cache/cache.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -379,11 +379,7 @@ class Cache {
379379
const reader = stream.getReader()
380380

381381
// 11.3
382-
readAllBytes(
383-
reader,
384-
(bytes) => bodyReadPromise.resolve(bytes),
385-
(error) => bodyReadPromise.reject(error)
386-
)
382+
readAllBytes(reader).then(bodyReadPromise.resolve, bodyReadPromise.reject)
387383
} else {
388384
bodyReadPromise.resolve(undefined)
389385
}

0 commit comments

Comments
 (0)