Conversation
A FormData from another source, such as Node.js' global FormData, passes the duck-typed isFormDataLike() check in the Request constructor, but extractBody() only serializes undici's own FormData. The request was then dispatched with a body that never produces data and hung forever. Throw an InvalidArgumentError for such bodies instead, as agreed in nodejs#5521, and document it for dispatch(). Fixes: nodejs#5520 Signed-off-by: v1teka <29147256+v1teka@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5894 +/- ##
=======================================
Coverage 93.98% 93.98%
=======================================
Files 110 110
Lines 40044 40059 +15
=======================================
+ Hits 37635 37650 +15
Misses 2409 2409 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Author
|
Hi @KhafraDev, could you share why this was closed? If the approach, the test or the docs line should be different, I'm happy to rework it. #5520 is still open, so I'd like to know what would make a fix for it acceptable. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This relates to...
Fixes #5520
Rationale
request()with Node's globalFormData(or any FormData that isn't undici's own) hangs forever: nothing is written to the socket and no error is raised. TheRequestconstructor accepts any FormData-like object, butextractBody()only serializes undici's ownFormData, so a foreign one ends up as a body stream that never produces data.#5521 took the "throw instead of encode" route that was agreed on there, but it was closed without being merged and #5520 is still open, so I picked it up with the same approach.
Changes
lib/core/request.js: a FormData-like body that fails thewebidl.is.FormDatabrand check now throwsInvalidArgumentError(the check is loaded lazily)test/client-request.js: a duck-typed FormData and Node's global FormData both reject, and the server never receives a request. Onmainthe test hangs until it times out.docs/docs/api/Dispatcher.md: one sentence on which FormDatabodyacceptsFeatures
N/A
Bug Fixes
request()/dispatch()with a FormData not created by undici rejects withInvalidArgumentErrorinstead of hangingBreaking Changes and Deprecations
N/A. These bodies never worked on v7/v8: 7.0–7.19 threw a TypeError, and 7.20+ hangs.
Status