Skip to content

form-data >= 2.3.2 fragments data, causing delays #422

@mildsunrise

Description

@mildsunrise

If you run the following with form-data v2.3.2:

const form = new (require("form-data"))()
form.append("foo", "Some text")
form.append("bar", "Hmmm")
form.submit("http://example.com")

You will see that it first sends an incomplete chunk of data to the server:

POST / HTTP/1.1
content-type: multipart/form-data; boundary=--------------------------602269624292240232678615
Host: example.com
Content-Length: 273
Connection: close

----------------------------602269624292240232678615
Content-Disposition: form-data; name="foo"

Some text

After that, Nagle's algorithm kicks in and blocks the remaining data until the server sends an ACK. Then it's sent:

 
----------------------------602269624292240232678615 
Content-Disposition: form-data; name="bar" 
 
Hmmm 
----------------------------602269624292240232678615-- 

In conclusion, all requests made with form-data have at least 1 RTT of delay added to them. This may not seem much (146ms for me), but for servers that are far away and/or lots of requests, it has a substantial impact.

We have tracked this down to felixge/node-combined-stream#38. Before that PR, data chunks were written synchronously and Node.JS could buffer them into a single write to the socket. After the change, buffering is not possible.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions