Skip to content

Cloning a Request with a FormData body hangs the process #52167

Closed
@kettanaito

Description

@kettanaito

Version

v18.19.0, v20.11.0, v21.7.0

Platform

Darwin Artems-Air.home 23.2.0 Darwin Kernel Version 23.2.0: Wed Nov 15 21:59:33 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T8112 arm64

Subsystem

No response

What steps will reproduce the bug?

// index.js
const data = new FormData()
data.set('foo', 'bar')

const request = new Request('http://localhost', { method: 'POST', body: data })
request.clone()
console.log('cloned')
node ./index.js

How often does it reproduce? Is there a required condition?

This reproduces reliably 100% of the time.

What is the expected behavior? Why is that the expected behavior?

The process exits with 0. If you replace the request body with any other supported value, the process does exit.

What do you see instead?

The process hangs forever, failing to execute request.clone() when a Request instance has FormData as its body. Seems to be sensitive to FormData with values. Removing the data.set(...) call makes the issue go away (nothing to copy while cloning the request, I presume).

Additional information

Originally reported in MSW: mswjs/msw#2078

Activity

kettanaito

kettanaito commented on Mar 20, 2024

@kettanaito
Author

This is also very likely an issue with Undici since that's what implements FormData (nodejs/undici#2413). Reporting it here for posterity mostly.

mcollina

mcollina commented on Mar 21, 2024

@mcollina
SponsorMember

This is fixed in undici v6.7.0. The fix for this will likely come to Node.js v21 very soon. Then we need to think what we want to do for Node.js v18 and v20 (which ships undici v5).

cc @nodejs/undici

kettanaito

kettanaito commented on Mar 21, 2024

@kettanaito
Author

@mcollina, incredible! Is the backport viable for the fix?

mcollina

mcollina commented on Mar 21, 2024

@mcollina
SponsorMember

I actually have no idea what fixed it, and if we should backport to v5 or just update v18 and v20 to latest undici.

kettanaito

kettanaito commented on Mar 21, 2024

@kettanaito
Author

If possible, updating Undici to the latest sounds like a good strategy 👍

mcollina

mcollina commented on Apr 19, 2024

@mcollina
SponsorMember

@nodejs/releasers any objections to update to Undici v6 in the next v20 release?

self-assigned this
on Apr 19, 2024
richardlau

richardlau commented on Apr 19, 2024

@richardlau
Member

@nodejs/releasers any objections to update to Undici v6 in the next v20 release?

No objections, on the basis that the change is not breaking for users of Node.js, but it may have to be done in a backport pull request as I'm not sure the commits will land cleanly as there were separate updates on Node.js 20 for Undici 5.x.

mcollina

mcollina commented on May 2, 2024

@mcollina
SponsorMember

@marco-ippolito the updates are already in #52793. Closing as this will come out in the next few days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @mcollina@richardlau@kettanaito

      Issue actions

        Cloning a Request with a FormData body hangs the process · Issue #52167 · nodejs/node