You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TypeError: fetch failed
at fetch (/node_modules/undici/index.js:115:13)
at async main (file://index.mjs:18:3) {
cause: RequestContentLengthMismatchError: Request body length does not match content-length header
at AsyncWriter.end (/node_modules/undici/lib/client.js:2257:15)
at writeIterable (/node_modules/undici/lib/client.js:2140:12) {
code: 'UND_ERR_REQ_CONTENT_LENGTH_MISMATCH'
}
}
Environment
Node: 20.9.0
Undici: 6.2.1
Additional context
This happens because the connection is destroyed after a redirect is received:
This doesn't happen when the redirect response ends immediately after sending the headers because the request is marked as completed before it's aborted, so the body is written as expected when the redirect is followed.
I was able to fix this by passing a flag to fetchParams.controller.connection.destroy() to destroy the connection without aborting the entire fetch, but I don't know if this is the right approach. If it is, I can send a PR.
The text was updated successfully, but these errors were encountered:
Bug Description
fetch
fails with aRequestContentLengthMismatchError
error when following a redirect under the following conditions:Reproducible By
fetch
fails with the following error:Environment
Additional context
This happens because the connection is destroyed after a redirect is received:
undici/lib/fetch/index.js
Line 1209 in d56cd7d
This causes the fetch to be aborted:
undici/lib/fetch/index.js
Lines 1721 to 1726 in d56cd7d
Afterwards, when the redirect is followed, the body is not written because the fetch was cancelled previously:
undici/lib/fetch/index.js
Lines 1833 to 1835 in d56cd7d
This results in an error because the content-length and the written bytes do not match:
undici/lib/client.js
Lines 2255 to 2261 in 871baa7
This doesn't happen when the redirect response ends immediately after sending the headers because the request is marked as completed before it's aborted, so the body is written as expected when the redirect is followed.
I was able to fix this by passing a flag to
fetchParams.controller.connection.destroy()
to destroy the connection without aborting the entire fetch, but I don't know if this is the right approach. If it is, I can send a PR.The text was updated successfully, but these errors were encountered: