Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9c70920

Browse filesBrowse files
nodejs-github-botRafaelGSS
authored andcommitted
deps: update undici to 6.19.8
PR-URL: #54456 Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent da6c61d commit 9c70920
Copy full SHA for 9c70920

File tree

Expand file treeCollapse file tree

11 files changed

+172
-87
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

11 files changed

+172
-87
lines changed
Open diff view settings
Collapse file

‎deps/undici/src/CONTRIBUTING.md‎

Copy file name to clipboardExpand all lines: deps/undici/src/CONTRIBUTING.md
+1Lines changed: 1 addition & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ an unbundled version instead of bundling one in `libnode.so`.
159159
To enable this, pass `EXTERNAL_PATH=/path/to/global/node_modules/undici` to `build/wasm.js`.
160160
Pass this path with `loader.js` appended to `--shared-builtin-undici/undici-path` in Node.js's `configure.py`.
161161
If building on a non-Alpine Linux distribution, you may need to also set the `WASM_CC`, `WASM_CFLAGS`, `WASM_LDFLAGS` and `WASM_LDLIBS` environment variables before running `build/wasm.js`.
162+
Similarly, you can set the `WASM_OPT` environment variable to utilize your own `wasm-opt` optimizer.
162163

163164
<a id="benchmarks"></a>
164165
### Benchmarks
Collapse file

‎deps/undici/src/build/wasm.js‎

Copy file name to clipboardExpand all lines: deps/undici/src/build/wasm.js
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const WASM_CC = process.env.WASM_CC || 'clang'
1414
let WASM_CFLAGS = process.env.WASM_CFLAGS || '--sysroot=/usr/share/wasi-sysroot -target wasm32-unknown-wasi'
1515
let WASM_LDFLAGS = process.env.WASM_LDFLAGS || ''
1616
const WASM_LDLIBS = process.env.WASM_LDLIBS || ''
17+
const WASM_OPT = process.env.WASM_OPT || './wasm-opt'
1718

1819
// For compatibility with Node.js' `configure --shared-builtin-undici/undici-path ...`
1920
const EXTERNAL_PATH = process.env.EXTERNAL_PATH
@@ -77,7 +78,7 @@ const hasApk = (function () {
7778
try { execSync('command -v apk'); return true } catch (error) { return false }
7879
})()
7980
const hasOptimizer = (function () {
80-
try { execSync('./wasm-opt --version'); return true } catch (error) { return false }
81+
try { execSync(`${WASM_OPT} --version`); return true } catch (error) { return false }
8182
})()
8283
if (hasApk) {
8384
// Gather information about the tools used for the build
@@ -97,7 +98,7 @@ ${join(WASM_SRC, 'src')}/*.c \
9798
${WASM_LDLIBS}`, { stdio: 'inherit' })
9899

99100
if (hasOptimizer) {
100-
execSync(`./wasm-opt ${WASM_OPT_FLAGS} -o ${join(WASM_OUT, 'llhttp.wasm')} ${join(WASM_OUT, 'llhttp.wasm')}`, { stdio: 'inherit' })
101+
execSync(`${WASM_OPT} ${WASM_OPT_FLAGS} -o ${join(WASM_OUT, 'llhttp.wasm')} ${join(WASM_OUT, 'llhttp.wasm')}`, { stdio: 'inherit' })
101102
}
102103
writeWasmChunk('llhttp.wasm', 'llhttp-wasm.js')
103104

@@ -109,7 +110,7 @@ ${join(WASM_SRC, 'src')}/*.c \
109110
${WASM_LDLIBS}`, { stdio: 'inherit' })
110111

111112
if (hasOptimizer) {
112-
execSync(`./wasm-opt ${WASM_OPT_FLAGS} --enable-simd -o ${join(WASM_OUT, 'llhttp_simd.wasm')} ${join(WASM_OUT, 'llhttp_simd.wasm')}`, { stdio: 'inherit' })
113+
execSync(`${WASM_OPT} ${WASM_OPT_FLAGS} --enable-simd -o ${join(WASM_OUT, 'llhttp_simd.wasm')} ${join(WASM_OUT, 'llhttp_simd.wasm')}`, { stdio: 'inherit' })
113114
}
114115
writeWasmChunk('llhttp_simd.wasm', 'llhttp_simd-wasm.js')
115116

Collapse file

‎deps/undici/src/lib/dispatcher/balanced-pool.js‎

Copy file name to clipboardExpand all lines: deps/undici/src/lib/dispatcher/balanced-pool.js
+22-3Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,23 @@ const kWeight = Symbol('kWeight')
2525
const kMaxWeightPerServer = Symbol('kMaxWeightPerServer')
2626
const kErrorPenalty = Symbol('kErrorPenalty')
2727

28+
/**
29+
* Calculate the greatest common divisor of two numbers by
30+
* using the Euclidean algorithm.
31+
*
32+
* @param {number} a
33+
* @param {number} b
34+
* @returns {number}
35+
*/
2836
function getGreatestCommonDivisor (a, b) {
29-
if (b === 0) return a
30-
return getGreatestCommonDivisor(b, a % b)
37+
if (a === 0) return b
38+
39+
while (b !== 0) {
40+
const t = b
41+
b = a % b
42+
a = t
43+
}
44+
return a
3145
}
3246

3347
function defaultFactory (origin, opts) {
@@ -105,7 +119,12 @@ class BalancedPool extends PoolBase {
105119
}
106120

107121
_updateBalancedPoolStats () {
108-
this[kGreatestCommonDivisor] = this[kClients].map(p => p[kWeight]).reduce(getGreatestCommonDivisor, 0)
122+
let result = 0
123+
for (let i = 0; i < this[kClients].length; i++) {
124+
result = getGreatestCommonDivisor(this[kClients][i][kWeight], result)
125+
}
126+
127+
this[kGreatestCommonDivisor] = result
109128
}
110129

111130
removeUpstream (upstream) {
Collapse file

‎deps/undici/src/lib/llhttp/wasm_build_env.txt‎

Copy file name to clipboardExpand all lines: deps/undici/src/lib/llhttp/wasm_build_env.txt
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11

2-
> undici@6.19.7 prebuild:wasm
2+
> undici@6.19.8 prebuild:wasm
33
> node build/wasm.js --prebuild
44

55
> docker build --platform=linux/x86_64 -t llhttp_wasm_builder -f /home/runner/work/node/node/deps/undici/src/build/Dockerfile /home/runner/work/node/node/deps/undici/src
66

77

88

9-
> undici@6.19.7 build:wasm
9+
> undici@6.19.8 build:wasm
1010
> node build/wasm.js --docker
1111

1212
> docker run --rm -t --platform=linux/x86_64 --user 1001:127 --mount type=bind,source=/home/runner/work/node/node/deps/undici/src/lib/llhttp,target=/home/node/undici/lib/llhttp llhttp_wasm_builder node build/wasm.js
Collapse file

‎deps/undici/src/lib/web/fetch/body.js‎

Copy file name to clipboardExpand all lines: deps/undici/src/lib/web/fetch/body.js
+27-5Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,25 @@ const { kState } = require('./symbols')
1616
const { webidl } = require('./webidl')
1717
const { Blob } = require('node:buffer')
1818
const assert = require('node:assert')
19-
const { isErrored } = require('../../core/util')
19+
const { isErrored, isDisturbed } = require('node:stream')
2020
const { isArrayBuffer } = require('node:util/types')
2121
const { serializeAMimeType } = require('./data-url')
2222
const { multipartFormDataParser } = require('./formdata-parser')
2323

2424
const textEncoder = new TextEncoder()
25+
function noop () {}
26+
27+
const hasFinalizationRegistry = globalThis.FinalizationRegistry && process.version.indexOf('v18') !== 0
28+
let streamRegistry
29+
30+
if (hasFinalizationRegistry) {
31+
streamRegistry = new FinalizationRegistry((weakRef) => {
32+
const stream = weakRef.deref()
33+
if (stream && !stream.locked && !isDisturbed(stream) && !isErrored(stream)) {
34+
stream.cancel('Response object has been garbage collected').catch(noop)
35+
}
36+
})
37+
}
2538

2639
// https://fetch.spec.whatwg.org/#concept-bodyinit-extract
2740
function extractBody (object, keepalive = false) {
@@ -264,14 +277,18 @@ function safelyExtractBody (object, keepalive = false) {
264277
return extractBody(object, keepalive)
265278
}
266279

267-
function cloneBody (body) {
280+
function cloneBody (instance, body) {
268281
// To clone a body body, run these steps:
269282

270283
// https://fetch.spec.whatwg.org/#concept-body-clone
271284

272285
// 1. Let « out1, out2 » be the result of teeing body’s stream.
273286
const [out1, out2] = body.stream.tee()
274287

288+
if (hasFinalizationRegistry) {
289+
streamRegistry.register(instance, new WeakRef(out1))
290+
}
291+
275292
// 2. Set body’s stream to out1.
276293
body.stream = out1
277294

@@ -414,7 +431,7 @@ async function consumeBody (object, convertBytesToJSValue, instance) {
414431

415432
// 1. If object is unusable, then return a promise rejected
416433
// with a TypeError.
417-
if (bodyUnusable(object[kState].body)) {
434+
if (bodyUnusable(object)) {
418435
throw new TypeError('Body is unusable: Body has already been read')
419436
}
420437

@@ -454,7 +471,9 @@ async function consumeBody (object, convertBytesToJSValue, instance) {
454471
}
455472

456473
// https://fetch.spec.whatwg.org/#body-unusable
457-
function bodyUnusable (body) {
474+
function bodyUnusable (object) {
475+
const body = object[kState].body
476+
458477
// An object including the Body interface mixin is
459478
// said to be unusable if its body is non-null and
460479
// its body’s stream is disturbed or locked.
@@ -496,5 +515,8 @@ module.exports = {
496515
extractBody,
497516
safelyExtractBody,
498517
cloneBody,
499-
mixinBody
518+
mixinBody,
519+
streamRegistry,
520+
hasFinalizationRegistry,
521+
bodyUnusable
500522
}
Collapse file

‎deps/undici/src/lib/web/fetch/request.js‎

Copy file name to clipboardExpand all lines: deps/undici/src/lib/web/fetch/request.js
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
'use strict'
44

5-
const { extractBody, mixinBody, cloneBody } = require('./body')
5+
const { extractBody, mixinBody, cloneBody, bodyUnusable } = require('./body')
66
const { Headers, fill: fillHeaders, HeadersList, setHeadersGuard, getHeadersGuard, setHeadersList, getHeadersList } = require('./headers')
77
const { FinalizationRegistry } = require('./dispatcher-weakref')()
88
const util = require('../../core/util')
@@ -557,7 +557,7 @@ class Request {
557557
// 40. If initBody is null and inputBody is non-null, then:
558558
if (initBody == null && inputBody != null) {
559559
// 1. If input is unusable, then throw a TypeError.
560-
if (util.isDisturbed(inputBody.stream) || inputBody.stream.locked) {
560+
if (bodyUnusable(input)) {
561561
throw new TypeError(
562562
'Cannot construct a Request with a Request object that has already been used.'
563563
)
@@ -759,7 +759,7 @@ class Request {
759759
webidl.brandCheck(this, Request)
760760

761761
// 1. If this is unusable, then throw a TypeError.
762-
if (this.bodyUsed || this.body?.locked) {
762+
if (bodyUnusable(this)) {
763763
throw new TypeError('unusable')
764764
}
765765

@@ -877,7 +877,7 @@ function cloneRequest (request) {
877877
// 2. If request’s body is non-null, set newRequest’s body to the
878878
// result of cloning request’s body.
879879
if (request.body != null) {
880-
newRequest.body = cloneBody(request.body)
880+
newRequest.body = cloneBody(newRequest, request.body)
881881
}
882882

883883
// 3. Return newRequest.
Collapse file

‎deps/undici/src/lib/web/fetch/response.js‎

Copy file name to clipboardExpand all lines: deps/undici/src/lib/web/fetch/response.js
+4-19Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict'
22

33
const { Headers, HeadersList, fill, getHeadersGuard, setHeadersGuard, setHeadersList } = require('./headers')
4-
const { extractBody, cloneBody, mixinBody } = require('./body')
4+
const { extractBody, cloneBody, mixinBody, hasFinalizationRegistry, streamRegistry, bodyUnusable } = require('./body')
55
const util = require('../../core/util')
66
const nodeUtil = require('node:util')
77
const { kEnumerableProperty } = util
@@ -26,24 +26,9 @@ const { URLSerializer } = require('./data-url')
2626
const { kConstruct } = require('../../core/symbols')
2727
const assert = require('node:assert')
2828
const { types } = require('node:util')
29-
const { isDisturbed, isErrored } = require('node:stream')
3029

3130
const textEncoder = new TextEncoder('utf-8')
3231

33-
const hasFinalizationRegistry = globalThis.FinalizationRegistry && process.version.indexOf('v18') !== 0
34-
let registry
35-
36-
if (hasFinalizationRegistry) {
37-
registry = new FinalizationRegistry((weakRef) => {
38-
const stream = weakRef.deref()
39-
if (stream && !stream.locked && !isDisturbed(stream) && !isErrored(stream)) {
40-
stream.cancel('Response object has been garbage collected').catch(noop)
41-
}
42-
})
43-
}
44-
45-
function noop () {}
46-
4732
// https://fetch.spec.whatwg.org/#response-class
4833
class Response {
4934
// Creates network error Response.
@@ -244,7 +229,7 @@ class Response {
244229
webidl.brandCheck(this, Response)
245230

246231
// 1. If this is unusable, then throw a TypeError.
247-
if (this.bodyUsed || this.body?.locked) {
232+
if (bodyUnusable(this)) {
248233
throw webidl.errors.exception({
249234
header: 'Response.clone',
250235
message: 'Body has already been consumed.'
@@ -327,7 +312,7 @@ function cloneResponse (response) {
327312
// 3. If response’s body is non-null, then set newResponse’s body to the
328313
// result of cloning response’s body.
329314
if (response.body != null) {
330-
newResponse.body = cloneBody(response.body)
315+
newResponse.body = cloneBody(newResponse, response.body)
331316
}
332317

333318
// 4. Return newResponse.
@@ -532,7 +517,7 @@ function fromInnerResponse (innerResponse, guard) {
532517
// a primitive or an object, even undefined. If the held value is an object, the registry keeps
533518
// a strong reference to it (so it can pass it to the cleanup callback later). Reworded from
534519
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry
535-
registry.register(response, new WeakRef(innerResponse.body.stream))
520+
streamRegistry.register(response, new WeakRef(innerResponse.body.stream))
536521
}
537522

538523
return response

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.