Skip to content
Open
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
16 changes: 12 additions & 4 deletions deps/undici/src/lib/dispatcher/client-h1.js
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ async function connectH1 (client, socket) {

function clearIdleSocketValidation (socket) {
if (socket[kIdleSocketValidationTimeout]) {
clearTimeout(socket[kIdleSocketValidationTimeout])
clearImmediate(socket[kIdleSocketValidationTimeout])
socket[kIdleSocketValidationTimeout] = null
}

Expand All @@ -885,15 +885,23 @@ function clearIdleSocketValidation (socket) {

function scheduleIdleSocketValidation (client, socket) {
socket[kIdleSocketValidation] = 1
socket[kIdleSocketValidationTimeout] = setTimeout(() => {
// Yield to the check phase (after poll) so unsolicited bytes / FIN / RST
// already pending on this idle keep-alive socket are processed before the
// next request is written (GHSA-35p6-xmwp-9g52).
//
// setTimeout(0) pays Node's ~1ms timer floor on every sequential reuse
// (#5493). setImmediate avoids that, but an *unref'd* Immediate lets poll
// block for ~500ms when the event loop is otherwise idle (#5600 / #5606).
// A ref'd Immediate both keeps the pending request alive and makes poll
// return immediately — the hybrid those issues asked for.
socket[kIdleSocketValidationTimeout] = setImmediate(() => {
socket[kIdleSocketValidationTimeout] = null
socket[kIdleSocketValidation] = 2

if (client[kSocket] === socket && !socket.destroyed) {
client[kResume]()
}
}, 0)
socket[kIdleSocketValidationTimeout].unref?.()
})
}

/**
Expand Down
32 changes: 29 additions & 3 deletions deps/undici/src/lib/handler/retry-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class RetryHandler {
this.end = null
this.etag = null
this.resume = null
this.headersSent = false

// Handle possible onConnect duplication
this.handler.onConnect(reason => {
Expand All @@ -102,6 +103,20 @@ class RetryHandler {
})
}

checkpointResponseEnd (headers, resume) {
if (this.end == null && this.opts.method !== 'HEAD') {
const contentLength = headers['content-length']
this.end = contentLength != null ? Number(contentLength) - 1 : null

assert(
this.end == null || Number.isFinite(this.end),
'invalid content-length'
)
}

this.resume = this.end != null ? resume : null
}

onRequestSent () {
if (this.handler.onRequestSent) {
this.handler.onRequestSent()
Expand Down Expand Up @@ -191,6 +206,8 @@ class RetryHandler {

if (statusCode >= 300) {
if (this.retryOpts.statusCodes.includes(statusCode) === false) {
this.headersSent = true
this.checkpointResponseEnd(headers, resume)
return this.handler.onHeaders(
statusCode,
rawHeaders,
Expand Down Expand Up @@ -259,8 +276,15 @@ class RetryHandler {

const { start, size, end = size - 1 } = contentRange

assert(this.start === start, 'content-range mismatch')
assert(this.end == null || this.end === end, 'content-range mismatch')
if (this.start !== start || (this.end != null && this.end !== end)) {
this.abort(
new RequestRetryError('Content-Range mismatch', statusCode, {
headers,
data: { count: this.retryCount }
})
)
return false
}

this.resume = resume
return true
Expand All @@ -272,6 +296,7 @@ class RetryHandler {
const range = parseRangeHeader(headers['content-range'])

if (range == null) {
this.headersSent = true
return this.handler.onHeaders(
statusCode,
rawHeaders,
Expand Down Expand Up @@ -310,6 +335,7 @@ class RetryHandler {
)

this.resume = resume
this.headersSent = true
this.etag = headers.etag != null ? headers.etag : null

// Weak etags are not useful for comparison nor cache
Expand Down Expand Up @@ -349,7 +375,7 @@ class RetryHandler {
}

onError (err) {
if (this.aborted || isDisturbed(this.opts.body)) {
if (this.aborted || isDisturbed(this.opts.body) || (this.headersSent && this.resume == null)) {
return this.handler.onError(err)
}

Expand Down
4 changes: 2 additions & 2 deletions deps/undici/src/lib/llhttp/wasm_build_env.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

> [email protected].0 prebuild:wasm
> [email protected].1 prebuild:wasm
> node build/wasm.js --prebuild

> 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



> [email protected].0 build:wasm
> [email protected].1 build:wasm
> node build/wasm.js --docker

> docker run --rm -t --platform=linux/x86_64 --user 1001:1001 --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
Expand Down
Loading
Loading