-
Notifications
You must be signed in to change notification settings - Fork 541
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
Invalid state: Controller is already closed #1564
Comments
Thanks for reporting! Can you provide steps to reproduce? We often need a reproducible example, e.g. some code that allows someone else to recreate your problem by just copying and pasting it. If it involves more than a couple of different file, create a new repository on GitHub and add a link to that. |
Yep, I'll try to provide an example, not very simple to create a minimal one. Think I found the PR which caused an issue in my case: #1511 |
So now I see that the reason is that when running tests with
DOMException instance is not an instance of Error, so Line 1857 in 26f60b7
is not true. But when simply running the same code with Node DOMException is an instance of Error. Previously (before undici v5.6.0 and #1511 in particular) there was custom Do not understand at the moment whether this is Jest problem or Undici's, or my own, and why DOMException is not an instance of Error in Jest case. |
We could make a isErrorLike helper which is a bit more forgiving. We've done this in other cases for increased interop. |
This is an undici issue caused by #1511. We still need a small repro for tests. |
I tried in Chrome and Firefox: > const d = new DOMException()
undefined
> d instanceof Error
true Seems it's an instance of Error, or I am missing sth? |
No, I was mistaken. However this seems more like a jest issue than an undici issue. edit: If possible, you could try using vitest, which includes a similar api to jest. I've seen some projects move away from jest and it seems like a good alternative. import { test, expect } from 'vitest'
test('test exception', async () => {
const d = new DOMException('')
expect(d).toBeInstanceOf(Error)
expect(d instanceof Error).toBeTruthy()
}) |
Thanks for a suggestion, I don't see a workaround from my side for this, I can open an issue in Jest repo if you think it should be fixed there and link it to this one, or possibly you see a good way (like the one @ronag suggested above or handling |
Jest has had an issue with |
Many thanks for helping with this, I tried to run tests with undici from the latest commit and it worked fine. |
I have the same problem with Node 20. Switching to Node 22 is working fine, however my cloud provider is using the LTS (20) and I can't move to 22 there. Any workaround to solve it? |
Stop using jest or use undici rather than the globals. Jest is bad. |
Bug Description
When running my tests with undici v5.8.0 I am getting the traceback:
I did some research if this can be helpful:
In my case the code in undici is getting exception in calling
await fetchParams.controller.next()
inlib/fetch/index.js
, so catch branch works:I added some console logging:
The detailed exception is:
So I suppose
fetchParams.controller.controller.enqueue(new Uint8Array(bytes))
is called even if the stream was aborted.Reproducible By
Create a new Node project with
npm init
Add jest:
Add test file
index.test.js
:Update
package.json
to have:Run
npm test
Expected Behavior
DOMException in Jest env does not extend Error, so stream aborting logic in
undici/lib/fetch/index.js
Line 1857 in 26f60b7
Environment
Node v18.2.0
Running tests with
jest
Additional context
This reproduces starting from undici v5.6.0
The text was updated successfully, but these errors were encountered: