undici
undici copied to clipboard
Tests not terminating after execution with msw when using FormData and Blob
Bug Description
I'm encountering an issue where the process does not terminate after running tests with msw
when using FormData
and Blob
. Removing the line where the Blob
is appended to the FormData
allows the tests to terminate as expected.
Reproducible By
Below is a simplified test case to illustrate the issue:
https://github.com/tokuhirom/msw-formdata-issue
~/work/msw-formdata-issue/ npm test
> [email protected] test
> mocha
test
{}
✔ test
1 passing (22ms)
When the above code is executed, the process does not terminate after running the test. However, if the line with formData.append(...)
is commented out, the process terminates correctly. It seems that the use of FormData in combination with Blob in msw setup is causing some resources to not be released properly.
Expected Behavior
exit the process after running all tests.
Logs & Screenshots
Environment
Node.js 21.1.0
Additional context
At first, I noted this issue to msw repo, but msw author suggest to post this issue to undici. ref. https://github.com/mswjs/msw/issues/1843
since this is likely an issue in blob, you'll have to post it in the node repo, preferably with a reproduction that doesn't use third party dependencies.
I have the same issue when passing whatever value to the FormData
, not only a Blob
, using the append
method.
It seems to me that it comes from the clone() method of body: https://github.com/nodejs/undici/blob/e495094b3700690f771089f1a3c338dd4da01b63/lib/fetch/body.js#L275
I've reported what looks like a duplicate of this: https://github.com/nodejs/node/issues/52167. Also includes a simple reproduction script without any third-parties. Cloning requests with FormData
body hangs forever (given that form data is not empty). Hasn't tested with blobs.
This is fixed here.