deps: update undici to 5.27.2 · nodejs/node@221f02d · GitHub
Skip to content

Commit 221f02d

Browse files
nodejs-github-botRafaelGSS
authored andcommitted
deps: update undici to 5.27.2
PR-URL: #50813 Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Matthew Aitken <maitken033380023@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 0e4d25e commit 221f02d

12 files changed

Lines changed: 1090 additions & 258 deletions

File tree

deps/undici/src/lib/client.js

Lines changed: 16 additions & 21 deletions

deps/undici/src/lib/core/request.js

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,29 @@ class Request {
112112

113113
this.method = method
114114

115+
this.abort = null
116+
115117
if (body == null) {
116118
this.body = null
117119
} else if (util.isStream(body)) {
118120
this.body = body
121+
122+
const rState = this.body._readableState
123+
if (!rState || !rState.autoDestroy) {
124+
this.endHandler = function autoDestroy () {
125+
util.destroy(this)
126+
}
127+
this.body.on('end', this.endHandler)
128+
}
129+
130+
this.errorHandler = err => {
131+
if (this.abort) {
132+
this.abort(err)
133+
} else {
134+
this.error = err
135+
}
136+
}
137+
this.body.on('error', this.errorHandler)
119138
} else if (util.isBuffer(body)) {
120139
this.body = body.byteLength ? body : null
121140
} else if (ArrayBuffer.isView(body)) {
@@ -236,7 +255,12 @@ class Request {
236255
assert(!this.aborted)
237256
assert(!this.completed)
238257

239-
return this[kHandler].onConnect(abort)
258+
if (this.error) {
259+
abort(this.error)
260+
} else {
261+
this.abort = abort
262+
return this[kHandler].onConnect(abort)
263+
}
240264
}
241265

242266
onHeaders (statusCode, headers, resume, statusText) {
@@ -265,6 +289,8 @@ class Request {
265289
}
266290

267291
onComplete (trailers) {
292+
this.onFinally()
293+
268294
assert(!this.aborted)
269295

270296
this.completed = true
@@ -275,6 +301,8 @@ class Request {
275301
}
276302

277303
onError (error) {
304+
this.onFinally()
305+
278306
if (channels.error.hasSubscribers) {
279307
channels.error.publish({ request: this, error })
280308
}
@@ -286,6 +314,18 @@ class Request {
286314
return this[kHandler].onError(error)
287315
}
288316

317+
onFinally () {
318+
if (this.errorHandler) {
319+
this.body.off('error', this.errorHandler)
320+
this.errorHandler = null
321+
}
322+
323+
if (this.endHandler) {
324+
this.body.off('end', this.endHandler)
325+
this.endHandler = null
326+
}
327+
}
328+
289329
// TODO: adjust to support H2
290330
addHeader (key, value) {
291331
processHeader(this, key, value)

deps/undici/src/lib/core/util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ function isReadableAborted (stream) {
190190
}
191191

192192
function destroy (stream, err) {
193-
if (!isStream(stream) || isDestroyed(stream)) {
193+
if (stream == null || !isStream(stream) || isDestroyed(stream)) {
194194
return
195195
}
196196

deps/undici/src/lib/pool.js

Lines changed: 1 addition & 1 deletion

deps/undici/src/node_modules/@fastify/busboy/lib/utils/decodeText.js

Lines changed: 97 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)