undici: TypeError: Invalid state: Writer has been released

ref:https://github.com/cloudflare/miniflare/issues/147

in vscode debugging, using will trigger an error.

image

     let res = await fetch("https://api.64clouds.com/v1/");

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 3
  • Comments: 22 (10 by maintainers)

Most upvoted comments

To ignore this, you can use:

error.message !== "Invalid state: Writer has been released" (set it for both of the two)

image image

@yemreak Yes, when using “node-fetch”, this error does not occur. This is my current workaround. (as stated above)

Hah, as GitHub automatically found above: The current version of Node.js (23.6) seems to have solved this bug with fetch(). It no longer occurs in my software. So I’m removing the workaround; use of the 3rd pary module “node-fetch”.

@Uzlopak can you reduce it to simple reproduction?

Did you try to use VSCode and in “Breakpoints” check the “Uncaught Exceptions” option? Uncaugt exceptions The error occurs in some finalization (cleanup) function / thread that is not needed to produce the correct output. So if you do not “break” on that, the program will seem to function normally. I suspect the exiting of Node.JS cleans something up that Undici still needs when handling the subsequent fetch callback. (Closes the writer stream) . When debugging a program, the option op catching “uncaught exceptions” is very handy for finding bugs…