Skip to content

Commit 9a4a7b7

Browse files
nodejs-github-bottargos
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 872856c commit 9a4a7b7

11 files changed

Lines changed: 172 additions & 87 deletions

File tree

‎deps/undici/src/CONTRIBUTING.md‎

Lines changed: 1 addition & 0 deletions
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
<aid="benchmarks"></a>
164165
### Benchmarks

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

Lines 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
letWASM_CFLAGS=process.env.WASM_CFLAGS||'--sysroot=/usr/share/wasi-sysroot -target wasm32-unknown-wasi'
1515
letWASM_LDFLAGS=process.env.WASM_LDFLAGS||''
1616
constWASM_LDLIBS=process.env.WASM_LDLIBS||''
17+
constWASM_OPT=process.env.WASM_OPT||'./wasm-opt'
1718

1819
// For compatibility with Node.js' `configure --shared-builtin-undici/undici-path ...`
1920
constEXTERNAL_PATH=process.env.EXTERNAL_PATH
@@ -77,7 +78,7 @@ const hasApk = (function () {
7778
try{execSync('command -v apk');returntrue}catch(error){returnfalse}
7879
})()
7980
consthasOptimizer=(function(){
80-
try{execSync('./wasm-opt --version');returntrue}catch(error){returnfalse}
81+
try{execSync(`${WASM_OPT} --version`);returntrue}catch(error){returnfalse}
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

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

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,23 @@ const kWeight = Symbol('kWeight')
2525
constkMaxWeightPerServer=Symbol('kMaxWeightPerServer')
2626
constkErrorPenalty=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
functiongetGreatestCommonDivisor(a,b){
29-
if(b===0)returna
30-
returngetGreatestCommonDivisor(b,a%b)
37+
if(a===0)returnb
38+
39+
while(b!==0){
40+
constt=b
41+
b=a%b
42+
a=t
43+
}
44+
returna
3145
}
3246

3347
functiondefaultFactory(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+
letresult=0
123+
for(leti=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){

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

Lines 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

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

Lines 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
constassert=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
consttextEncoder=newTextEncoder()
25+
functionnoop(){}
26+
27+
consthasFinalizationRegistry=globalThis.FinalizationRegistry&&process.version.indexOf('v18')!==0
28+
letstreamRegistry
29+
30+
if(hasFinalizationRegistry){
31+
streamRegistry=newFinalizationRegistry((weakRef)=>{
32+
conststream=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
functionextractBody(object,keepalive=false){
@@ -264,14 +277,18 @@ function safelyExtractBody (object, keepalive = false) {
264277
returnextractBody(object,keepalive)
265278
}
266279

267-
functioncloneBody(body){
280+
functioncloneBody(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,newWeakRef(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
thrownewTypeError('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-
functionbodyUnusable(body){
474+
functionbodyUnusable(object){
475+
constbody=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
}

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

Lines 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
constutil=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
thrownewTypeError(
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
thrownewTypeError('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.

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

Lines 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
constutil=require('../../core/util')
66
constnodeUtil=require('node:util')
77
const{ kEnumerableProperty }=util
@@ -26,24 +26,9 @@ const { URLSerializer } = require('./data-url')
2626
const{ kConstruct }=require('../../core/symbols')
2727
constassert=require('node:assert')
2828
const{ types }=require('node:util')
29-
const{ isDisturbed, isErrored }=require('node:stream')
3029

3130
consttextEncoder=newTextEncoder('utf-8')
3231

33-
consthasFinalizationRegistry=globalThis.FinalizationRegistry&&process.version.indexOf('v18')!==0
34-
letregistry
35-
36-
if(hasFinalizationRegistry){
37-
registry=newFinalizationRegistry((weakRef)=>{
38-
conststream=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-
functionnoop(){}
46-
4732
// https://fetch.spec.whatwg.org/#response-class
4833
classResponse{
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
throwwebidl.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,newWeakRef(innerResponse.body.stream))
520+
streamRegistry.register(response,newWeakRef(innerResponse.body.stream))
536521
}
537522

538523
returnresponse

0 commit comments

Comments
 (0)