-
Notifications
You must be signed in to change notification settings - Fork 572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nondescriptive Typeerror: Cannot read properties of undefined (reading 'reason')
#1776
Comments
Cannot read properties of undefined (reading 'reason')
This is an issue in fetch where the controller doesn't have a terminated property (likely got removed a while ago) Line 439 in b041f9a
|
Hmm okay. I need to crawl the call stack for this then and see why the controller doesn't have a terminated property. It might be a simple |
This is related to redirect follow I think
Notice the trailing |
node-fetch does not have this problem |
Yeah, it's definitely related to redirects; I couldn't figure out a way to replicate it locally though. The actual issue is that the connection is being destroyed due to the redirect mode being set to 'follow'. Here's a diff that fixes the issue, but definitely breaks some other things. diff --git a/lib/fetch/index.js b/lib/fetch/index.js
index 6c67c1e..2ddbcfd 100644
--- a/lib/fetch/index.js
+++ b/lib/fetch/index.js
@@ -1069,7 +1069,7 @@ async function httpFetch (fetchParams) {
// encouraged to, transmit an RST_STREAM frame.
// See, https://github.com/whatwg/fetch/issues/1288
if (request.redirect !== 'manual') {
- fetchParams.controller.connection.destroy()
+ // fetchParams.controller.connection.destroy()
}
// 2. Switch on request’s redirect mode:
@@ -1562,7 +1562,7 @@ async function httpNetworkFetch (
includeCredentials = false,
forceNewConnection = false
) {
- assert(!fetchParams.controller.connection || fetchParams.controller.connection.destroyed)
+ // assert(!fetchParams.controller.connection || fetchParams.controller.connection.destroyed)
fetchParams.controller.connection = {
abort: null,
diff --git a/lib/fetch/response.js b/lib/fetch/response.js
index 9c9d628..a991ea0 100644
--- a/lib/fetch/response.js
+++ b/lib/fetch/response.js
@@ -436,7 +436,7 @@ function makeAppropriateNetworkError (fetchParams) {
// otherwise return a network error.
return isAborted(fetchParams)
? makeNetworkError(new DOMException('The operation was aborted.', 'AbortError'))
- : makeNetworkError(fetchParams.controller.terminated.reason)
+ : makeNetworkError(new TypeError('request failed'))
}
// https://whatpr.org/fetch/1392.html#initialize-a-response |
Actually all the tests pass. cc @ronag |
I have this as well |
repro: const { createServer } = require('node:http');
const { fetch } = require('.');
createServer((req, res) => {
if (req.url === '/redirect') {
res.statusCode = 301;
res.setHeader('location', '/redirect/');
res.write('<a href="/redirect/">Moved Permanently</a>');
setTimeout(() => res.end(), 500);
return;
}
res.write(req.url);
res.end();
}).listen(3000, async () => {
console.log('listen');
const resp = await fetch('http://localhost:3000/redirect');
console.log(await resp.text());
}); broken on commit 6883ba5 |
Thanks! I figured out the reasoning this broke too. We destroy the old connection on redirect, causing the condition in 6883ba5 to get triggered. Will post a PR to fix this soon. |
Due to a bug in undici (nodejs/undici#1776) that is affecting many versions of Node and Next.js, we want a workaround to ensure our users don't see this. Therefore, we're forking isomorphic-unfetch to always use node-fetch on Node to avoid falling back to global.fetch (undici). Also, isomorphic-unfetch was polyfilling, which we want to avoid.
Due to a bug in undici (nodejs/undici#1776) that is affecting many versions of Node and Next.js, we want a workaround to ensure our users don't see this. Therefore, we're forking isomorphic-unfetch to always use node-fetch on Node to avoid falling back to global.fetch (undici). Also, isomorphic-unfetch was polyfilling, which we want to avoid.
Due to a bug in undici (nodejs/undici#1776) that is affecting many versions of Node and Next.js, we want a workaround to ensure our users don't see this. Therefore, we're forking isomorphic-unfetch to always use node-fetch on Node to avoid falling back to global.fetch (undici). Also, isomorphic-unfetch was polyfilling, which we want to avoid.
If someone else also stumbles upon this - I had the same error ( The solution for me was to remove the |
Bug Description
Got a strange error using
fetch
,The code is private, but the line that caused this is:
const response = await fetch(`https://nodejs.org/dist/latest-v${major}.x`);
. I'm investigating now. Most likely an issue on my end but we may be able to benefit from a better error message here.Reproducible By
Expected Behavior
Logs & Screenshots
Environment
Additional context
The text was updated successfully, but these errors were encountered: