Skip to content

Commit 828ad42

Browse files
deps: update undici to 6.3.0
PR-URL: #51462 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent d755f1a commit 828ad42

31 files changed

+2924
-656
lines changed

deps/undici/src/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ Returns a promise with the result of the `Dispatcher.request` method.
119119

120120
Calls `options.dispatcher.request(options)`.
121121

122-
See [Dispatcher.request](./docs/api/Dispatcher.md#dispatcherrequestoptions-callback) for more details.
122+
See [Dispatcher.request](./docs/api/Dispatcher.md#dispatcherrequestoptions-callback) for more details, and [request examples](./examples/README.md) for examples.
123123

124124
### `undici.stream([url, options, ]factory): Promise`
125125

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

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Debug
2+
3+
Undici (and subsenquently `fetch` and `websocket`) exposes a debug statement that can be enabled by setting `NODE_DEBUG` within the environment.
4+
5+
The flags availabile are:
6+
7+
## `undici`
8+
9+
This flag enables debug statements for the core undici library.
10+
11+
```sh
12+
NODE_DEBUG=undici node script.js
13+
14+
UNDICI 16241: connecting to nodejs.org using https:h1
15+
UNDICI 16241: connecting to nodejs.org using https:h1
16+
UNDICI 16241: connected to nodejs.org using https:h1
17+
UNDICI 16241: sending request to GET https://nodejs.org//
18+
UNDICI 16241: received response to GET https://nodejs.org// - HTTP 307
19+
UNDICI 16241: connecting to nodejs.org using https:h1
20+
UNDICI 16241: trailers received from GET https://nodejs.org//
21+
UNDICI 16241: connected to nodejs.org using https:h1
22+
UNDICI 16241: sending request to GET https://nodejs.org//en
23+
UNDICI 16241: received response to GET https://nodejs.org//en - HTTP 200
24+
UNDICI 16241: trailers received from GET https://nodejs.org//en
25+
```
26+
27+
## `fetch`
28+
29+
This flag enables debug statements for the `fetch` API.
30+
31+
> **Note**: statements are pretty similar to the ones in the `undici` flag, but scoped to `fetch`
32+
33+
```sh
34+
NODE_DEBUG=fetch node script.js
35+
36+
FETCH 16241: connecting to nodejs.org using https:h1
37+
FETCH 16241: connecting to nodejs.org using https:h1
38+
FETCH 16241: connected to nodejs.org using https:h1
39+
FETCH 16241: sending request to GET https://nodejs.org//
40+
FETCH 16241: received response to GET https://nodejs.org// - HTTP 307
41+
FETCH 16241: connecting to nodejs.org using https:h1
42+
FETCH 16241: trailers received from GET https://nodejs.org//
43+
FETCH 16241: connected to nodejs.org using https:h1
44+
FETCH 16241: sending request to GET https://nodejs.org//en
45+
FETCH 16241: received response to GET https://nodejs.org//en - HTTP 200
46+
FETCH 16241: trailers received from GET https://nodejs.org//en
47+
```
48+
49+
## `websocket`
50+
51+
This flag enables debug statements for the `Websocket` API.
52+
53+
> **Note**: statements can overlap with `UNDICI` ones if `undici` or `fetch` flag has been enabled as well.
54+
55+
```sh
56+
NODE_DEBUG=fetch node script.js
57+
58+
WEBSOCKET 18309: connecting to echo.websocket.org using https:h1
59+
WEBSOCKET 18309: connected to echo.websocket.org using https:h1
60+
WEBSOCKET 18309: sending request to GET https://echo.websocket.org//
61+
WEBSOCKET 18309: connection opened <ip_address>
62+
```

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ You can not assume that this event is related to any specific request.
105105
import diagnosticsChannel from 'diagnostics_channel'
106106

107107
diagnosticsChannel.channel('undici:client:beforeConnect').subscribe(({ connectParams, connector }) => {
108-
// const { host, hostname, protocol, port, servername } = connectParams
108+
// const { host, hostname, protocol, port, servername, version } = connectParams
109109
// connector is a function that creates the socket
110110
})
111111
```
@@ -118,7 +118,7 @@ This message is published after a connection is established.
118118
import diagnosticsChannel from 'diagnostics_channel'
119119

120120
diagnosticsChannel.channel('undici:client:connected').subscribe(({ socket, connectParams, connector }) => {
121-
// const { host, hostname, protocol, port, servername } = connectParams
121+
// const { host, hostname, protocol, port, servername, version } = connectParams
122122
// connector is a function that creates the socket
123123
})
124124
```
@@ -131,7 +131,7 @@ This message is published if it did not succeed to create new connection
131131
import diagnosticsChannel from 'diagnostics_channel'
132132

133133
diagnosticsChannel.channel('undici:client:connectError').subscribe(({ error, socket, connectParams, connector }) => {
134-
// const { host, hostname, protocol, port, servername } = connectParams
134+
// const { host, hostname, protocol, port, servername, version } = connectParams
135135
// connector is a function that creates the socket
136136
console.log(`Connect failed with ${error.message}`)
137137
})

deps/undici/src/index-fetch.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ const fetchImpl = require('./lib/fetch').fetch
44

55
module.exports.fetch = function fetch (resource, init = undefined) {
66
return fetchImpl(resource, init).catch((err) => {
7-
Error.captureStackTrace(err, this)
7+
if (typeof err === 'object') {
8+
Error.captureStackTrace(err, this)
9+
}
810
throw err
911
})
1012
}

deps/undici/src/lib/api/abort-signal.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ const kSignal = Symbol('kSignal')
66

77
function abort (self) {
88
if (self.abort) {
9-
self.abort()
9+
self.abort(self[kSignal]?.reason)
1010
} else {
11-
self.onError(new RequestAbortedError())
11+
self.onError(self[kSignal]?.reason ?? new RequestAbortedError())
1212
}
1313
}
1414

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

+13-7
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,12 @@ class Cache {
112112
// 5.5.2
113113
for (const response of responses) {
114114
// 5.5.2.1
115-
const responseObject = new Response(response.body?.source ?? null)
116-
const body = responseObject[kState].body
115+
const responseObject = new Response(null)
117116
responseObject[kState] = response
118-
responseObject[kState].body = body
119117
responseObject[kHeaders][kHeadersList] = response.headersList
120118
responseObject[kHeaders][kGuard] = 'immutable'
121119

122-
responseList.push(responseObject)
120+
responseList.push(responseObject.clone())
123121
}
124122

125123
// 6.
@@ -146,16 +144,24 @@ class Cache {
146144
webidl.brandCheck(this, Cache)
147145
webidl.argumentLengthCheck(arguments, 1, { header: 'Cache.addAll' })
148146

149-
requests = webidl.converters['sequence<RequestInfo>'](requests)
150-
151147
// 1.
152148
const responsePromises = []
153149

154150
// 2.
155151
const requestList = []
156152

157153
// 3.
158-
for (const request of requests) {
154+
for (let request of requests) {
155+
if (request === undefined) {
156+
throw webidl.errors.conversionFailed({
157+
prefix: 'Cache.addAll',
158+
argument: 'Argument 1',
159+
types: ['undefined is not allowed']
160+
})
161+
}
162+
163+
request = webidl.converters.RequestInfo(request)
164+
159165
if (typeof request === 'string') {
160166
continue
161167
}

deps/undici/src/lib/client.js

+30-29
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const net = require('net')
99
const http = require('http')
1010
const { pipeline } = require('stream')
1111
const util = require('./core/util')
12+
const { channels } = require('./core/diagnostics')
1213
const timers = require('./timers')
1314
const Request = require('./core/request')
1415
const DispatcherBase = require('./dispatcher-base')
@@ -108,21 +109,6 @@ const FastBuffer = Buffer[Symbol.species]
108109

109110
const kClosedResolve = Symbol('kClosedResolve')
110111

111-
const channels = {}
112-
113-
try {
114-
const diagnosticsChannel = require('diagnostics_channel')
115-
channels.sendHeaders = diagnosticsChannel.channel('undici:client:sendHeaders')
116-
channels.beforeConnect = diagnosticsChannel.channel('undici:client:beforeConnect')
117-
channels.connectError = diagnosticsChannel.channel('undici:client:connectError')
118-
channels.connected = diagnosticsChannel.channel('undici:client:connected')
119-
} catch {
120-
channels.sendHeaders = { hasSubscribers: false }
121-
channels.beforeConnect = { hasSubscribers: false }
122-
channels.connectError = { hasSubscribers: false }
123-
channels.connected = { hasSubscribers: false }
124-
}
125-
126112
/**
127113
* @type {import('../types/client').default}
128114
*/
@@ -1191,6 +1177,7 @@ async function connect (client) {
11911177
hostname,
11921178
protocol,
11931179
port,
1180+
version: client[kHTTPConnVersion],
11941181
servername: client[kServerName],
11951182
localAddress: client[kLocalAddress]
11961183
},
@@ -1284,6 +1271,7 @@ async function connect (client) {
12841271
hostname,
12851272
protocol,
12861273
port,
1274+
version: client[kHTTPConnVersion],
12871275
servername: client[kServerName],
12881276
localAddress: client[kLocalAddress]
12891277
},
@@ -1306,6 +1294,7 @@ async function connect (client) {
13061294
hostname,
13071295
protocol,
13081296
port,
1297+
version: client[kHTTPConnVersion],
13091298
servername: client[kServerName],
13101299
localAddress: client[kLocalAddress]
13111300
},
@@ -1658,19 +1647,6 @@ function writeH2 (client, session, request) {
16581647
return false
16591648
}
16601649

1661-
try {
1662-
// TODO(HTTP/2): Should we call onConnect immediately or on stream ready event?
1663-
request.onConnect((err) => {
1664-
if (request.aborted || request.completed) {
1665-
return
1666-
}
1667-
1668-
errorRequest(client, request, err || new RequestAbortedError())
1669-
})
1670-
} catch (err) {
1671-
errorRequest(client, request, err)
1672-
}
1673-
16741650
if (request.aborted) {
16751651
return false
16761652
}
@@ -1682,9 +1658,34 @@ function writeH2 (client, session, request) {
16821658
headers[HTTP2_HEADER_AUTHORITY] = host || client[kHost]
16831659
headers[HTTP2_HEADER_METHOD] = method
16841660

1661+
try {
1662+
// We are already connected, streams are pending.
1663+
// We can call on connect, and wait for abort
1664+
request.onConnect((err) => {
1665+
if (request.aborted || request.completed) {
1666+
return
1667+
}
1668+
1669+
err = err || new RequestAbortedError()
1670+
1671+
if (stream != null) {
1672+
util.destroy(stream, err)
1673+
1674+
h2State.openStreams -= 1
1675+
if (h2State.openStreams === 0) {
1676+
session.unref()
1677+
}
1678+
}
1679+
1680+
errorRequest(client, request, err)
1681+
})
1682+
} catch (err) {
1683+
errorRequest(client, request, err)
1684+
}
1685+
16851686
if (method === 'CONNECT') {
16861687
session.ref()
1687-
// we are already connected, streams are pending, first request
1688+
// We are already connected, streams are pending, first request
16881689
// will create a new stream. We trigger a request to create the stream and wait until
16891690
// `ready` event is triggered
16901691
// We disabled endStream to allow the user to write to the stream

deps/undici/src/lib/compat/dispatcher-weakref.js

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class CompatFinalizer {
2828
})
2929
}
3030
}
31+
32+
unregister (key) {}
3133
}
3234

3335
module.exports = function () {

0 commit comments

Comments
 (0)