Skip to content
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

v0.2.0: Request to some URLs (with redirect?) causes ERR_INVALID_STATE error #3

Open
haxibami opened this issue Dec 11, 2023 · 1 comment

Comments

@haxibami
Copy link

Bug

When using this library to fetch metadata on https://nextjs.org/docs/app/building-your-application/routing/router-handlers, which normally is redirected to https://nextjs.org/docs/app/building-your-application/routing/route-handlers, an error occurs and process fails. This doesn't happen with v0.1.3 or below.

Environment

Linux / Node.js v21.4.0 / fetch-site-metadata v0.2.0

Minimal reproduction code:

import fetchSiteMetadata from "fetch-site-metadata";

const url =
  "https://nextjs.org/docs/app/building-your-application/routing/router-handlers";
const result = await fetchSiteMetadata(url);

console.log(result);

Output

node:internal/webstreams/readablestream:1078
      throw new ERR_INVALID_STATE.TypeError('Controller is already closed');
            ^

TypeError [ERR_INVALID_STATE]: Invalid state: Controller is already closed
    at ReadableStreamDefaultController.enqueue (node:internal/webstreams/readablestream:1078:13)
    at fetchParams.controller.resume (node:internal/deps/undici/undici:10994:45)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  code: 'ERR_INVALID_STATE'
}

Node.js v21.4.0
@fabon-f
Copy link
Owner

fabon-f commented Feb 11, 2025

Maybe the migration from node-fetch package to native fetch causes the bug, which means it should be a bug of undici, a HTTP library used behind Node.js's native fetch.

Now I confirmed that Node.js v18 still crashes with the reproduction, whereas v20, v22, v23 don't crash. It suggest that an upstream bug caused this issue is fixed in undici v6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants