Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

deps: update undici to 7.2.1 #56569

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deps/undici/src/docs/docs/api/DiagnosticsChannel.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ diagnosticsChannel.channel('undici:request:bodySent').subscribe(({ request }) =>

## `undici:request:headers`

This message is published after the response headers have been received, i.e. the response has been completed.
This message is published after the response headers have been received.

```js
import diagnosticsChannel from 'diagnostics_channel'
Expand Down
2 changes: 1 addition & 1 deletion deps/undici/src/docs/docs/api/Dispatcher.md
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ return null

A faster version of `Dispatcher.request`. This method expects the second argument `factory` to return a [`stream.Writable`](https://nodejs.org/api/stream.html#stream_class_stream_writable) stream which the response will be written to. This improves performance by avoiding creating an intermediate [`stream.Readable`](https://nodejs.org/api/stream.html#stream_readable_streams) stream when the user expects to directly pipe the response body to a [`stream.Writable`](https://nodejs.org/api/stream.html#stream_class_stream_writable) stream.

As demonstrated in [Example 1 - Basic GET stream request](/docs/docs/api/Dispatcher.md#example-1---basic-get-stream-request), it is recommended to use the `option.opaque` property to avoid creating a closure for the `factory` method. This pattern works well with Node.js Web Frameworks such as [Fastify](https://fastify.io). See [Example 2 - Stream to Fastify Response](/docs/docs/api/Dispatch.md#example-2---stream-to-fastify-response) for more details.
As demonstrated in [Example 1 - Basic GET stream request](/docs/docs/api/Dispatcher.md#example-1-basic-get-stream-request), it is recommended to use the `option.opaque` property to avoid creating a closure for the `factory` method. This pattern works well with Node.js Web Frameworks such as [Fastify](https://fastify.io). See [Example 2 - Stream to Fastify Response](/docs/docs/api/Dispatch.md#example-2-stream-to-fastify-response) for more details.

Arguments:

Expand Down
4 changes: 2 additions & 2 deletions deps/undici/src/lib/handler/retry-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class RetryHandler {
? Math.min(retryAfterHeader, maxTimeout)
: Math.min(minTimeout * timeoutFactor ** (counter - 1), maxTimeout)

setTimeout(() => cb(null), retryTimeout).unref()
setTimeout(() => cb(null), retryTimeout)
}

onResponseStart (controller, statusCode, headers, statusMessage) {
Expand Down Expand Up @@ -277,7 +277,7 @@ class RetryHandler {
}

onResponseError (controller, err) {
if (!controller || controller.aborted || isDisturbed(this.opts.body)) {
if (controller?.aborted || isDisturbed(this.opts.body)) {
this.handler.onResponseError?.(controller, err)
return
}
Expand Down
2 changes: 1 addition & 1 deletion deps/undici/src/lib/interceptor/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ module.exports = interceptorOpts => {

instance.runLookup(origin, origDispatchOpts, (err, newOrigin) => {
if (err) {
return handler.onError(err)
return handler.onResponseError(null, err)
}

let dispatchOpts = null
Expand Down
2 changes: 1 addition & 1 deletion deps/undici/src/lib/llhttp/wasm_build_env.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

> undici@7.2.0 build:wasm
> undici@7.2.1 build:wasm
> node build/wasm.js --docker

> docker run --rm --platform=linux/x86_64 --user 1001:128 --mount type=bind,source=/home/runner/work/node/node/deps/undici/src/lib/llhttp,target=/home/node/build/lib/llhttp --mount type=bind,source=/home/runner/work/node/node/deps/undici/src/build,target=/home/node/build/build --mount type=bind,source=/home/runner/work/node/node/deps/undici/src/deps,target=/home/node/build/deps -t ghcr.io/nodejs/wasm-builder@sha256:975f391d907e42a75b8c72eb77c782181e941608687d4d8694c3e9df415a0970 node build/wasm.js
Expand Down
88 changes: 61 additions & 27 deletions deps/undici/src/lib/web/websocket/receiver.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const { PerMessageDeflate } = require('./permessage-deflate')

class ByteParser extends Writable {
#buffers = []
#fragmentsBytes = 0
#byteOffset = 0
#loop = false

Expand Down Expand Up @@ -208,16 +209,14 @@ class ByteParser extends Writable {
this.#state = parserStates.INFO
} else {
if (!this.#info.compressed) {
this.#fragments.push(body)
this.writeFragments(body)

// If the frame is not fragmented, a message has been received.
// If the frame is fragmented, it will terminate with a fin bit set
// and an opcode of 0 (continuation), therefore we handle that when
// parsing continuation frames, not here.
if (!this.#info.fragmented && this.#info.fin) {
const fullMessage = Buffer.concat(this.#fragments)
websocketMessageReceived(this.#handler, this.#info.binaryType, fullMessage)
this.#fragments.length = 0
websocketMessageReceived(this.#handler, this.#info.binaryType, this.consumeFragments())
}

this.#state = parserStates.INFO
Expand All @@ -228,7 +227,7 @@ class ByteParser extends Writable {
return
}

this.#fragments.push(data)
this.writeFragments(data)

if (!this.#info.fin) {
this.#state = parserStates.INFO
Expand All @@ -237,11 +236,10 @@ class ByteParser extends Writable {
return
}

websocketMessageReceived(this.#handler, this.#info.binaryType, Buffer.concat(this.#fragments))
websocketMessageReceived(this.#handler, this.#info.binaryType, this.consumeFragments())

this.#loop = true
this.#state = parserStates.INFO
this.#fragments.length = 0
this.run(callback)
})

Expand All @@ -265,34 +263,70 @@ class ByteParser extends Writable {
return emptyBuffer
}

if (this.#buffers[0].length === n) {
this.#byteOffset -= this.#buffers[0].length
this.#byteOffset -= n

const first = this.#buffers[0]

if (first.length > n) {
// replace with remaining buffer
this.#buffers[0] = first.subarray(n, first.length)
return first.subarray(0, n)
} else if (first.length === n) {
// prefect match
return this.#buffers.shift()
} else {
let offset = 0
// If Buffer.allocUnsafe is used, extra copies will be made because the offset is non-zero.
const buffer = Buffer.allocUnsafeSlow(n)
while (offset !== n) {
const next = this.#buffers[0]
const length = next.length

if (length + offset === n) {
buffer.set(this.#buffers.shift(), offset)
break
} else if (length + offset > n) {
buffer.set(next.subarray(0, n - offset), offset)
this.#buffers[0] = next.subarray(n - offset)
break
} else {
buffer.set(this.#buffers.shift(), offset)
offset += length
}
}

return buffer
}
}

writeFragments (fragment) {
this.#fragmentsBytes += fragment.length
this.#fragments.push(fragment)
}

consumeFragments () {
const fragments = this.#fragments

if (fragments.length === 1) {
// single fragment
this.#fragmentsBytes = 0
return fragments.shift()
}

const buffer = Buffer.allocUnsafe(n)
let offset = 0
// If Buffer.allocUnsafe is used, extra copies will be made because the offset is non-zero.
const output = Buffer.allocUnsafeSlow(this.#fragmentsBytes)

while (offset !== n) {
const next = this.#buffers[0]
const { length } = next

if (length + offset === n) {
buffer.set(this.#buffers.shift(), offset)
break
} else if (length + offset > n) {
buffer.set(next.subarray(0, n - offset), offset)
this.#buffers[0] = next.subarray(n - offset)
break
} else {
buffer.set(this.#buffers.shift(), offset)
offset += next.length
}
for (let i = 0; i < fragments.length; ++i) {
const buffer = fragments[i]
output.set(buffer, offset)
offset += buffer.length
}

this.#byteOffset -= n
this.#fragments = []
this.#fragmentsBytes = 0

return buffer
return output
}

parseCloseBody (data) {
Expand Down
2 changes: 1 addition & 1 deletion deps/undici/src/lib/web/websocket/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function toArrayBuffer (buffer) {
if (buffer.byteLength === buffer.buffer.byteLength) {
return buffer.buffer
}
return buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength)
return new Uint8Array(buffer).buffer
}

/**
Expand Down
Loading
Loading