node-formidable / formidable

The most used, flexible, fast and streaming parser for multipart form data. Supports uploading to serverless environments, AWS S3, Azure, GCP or the filesystem. Used in production.
MIT License
7k stars 680 forks source link

IncomingForm end event emitted twice (at least) #810

Closed dresende closed 2 years ago

dresende commented 2 years ago

Support plan

Context

What are you trying to achieve or the steps to reproduce?

let form = new formidable.IncomingForm();

form.on("field", (field, value) => {
    console.log("field", field, value);
});

form.on("end", () => {
    console.log("end");
});

What was the result you got?

Printed "end" twice.

What result did you expect?

Print "end" once. I tested with a simple Postman form with 2 fields.

I bypassed the error using form.once("end") but this doesn't feel right.

GrosSacASac commented 2 years ago

I 'll have a look

tunnckoCore commented 2 years ago

Interesting.

@dresende when 3 fields, does it emit 3 times? Try mixing fields types too: 3 fields and 1 file - emit 3-4 times?

Should add test in test/unit/formidable.test.js to check it's emitted once. Also all the cases.

Hm.

dresende commented 2 years ago

No, it seems to just emit 2 events, no matter if I have 2 or 3 fields. I was using multipart for form-data (fields and files) but had no files. But since I had no files I also tested with x-www-form-urlencoded and same thing happens.

I might have hit a very very specific case, or not.. I use formidable for years now but I updated recently from 1.2.2 to 2.0.1. I made the necessary changes and I use it for a lot of forms on my app, only this one seems to have some kind of glitch.

dresende commented 2 years ago

Just tested with only 1 field and it still emits 2 events. And... this only occurs for form-data body type.

tunnckoCore commented 2 years ago

Thanks for testing.

Hm, yea.. definitely strange. We should look and follow the whole flow more carefully .

LatenC commented 2 years ago

Same issue happened with me also. I am also using the same version - 2.0.1

Fedacc commented 2 years ago

I see the same issue also on version 2.0.0, event 'end' is emitted twice regardless of the number of files/fields received

GrosSacASac commented 2 years ago

Published as 3.2.3

marcorocci commented 1 year ago

the problem is in this part form.on("end", () => { console.log("end"); });

should be form.once("end", () => { console.log("end"); });

so once instead of on

GrosSacASac commented 1 year ago

@marcorocci true but the library should also not emit end twice to begin with

dresende commented 1 year ago

so once instead of on

That's obvious and that's how people worked around it until it is/was fixed.

wbt commented 1 year ago

That's obvious

Just about nothing is "obvious" to everybody. The original comment was intended to be helpful and could have been to folks who hadn't encountered that idea yet; no need to be dismissive.

dresende commented 1 year ago

Just about nothing is "obvious" to everybody.

That's obvious or a paradox? 😂

julientype commented 1 year ago

once done <<<< yes that ok as API ..... end is used for like body parts then flags the next part .... Like end flags 2 times its probably socket or phrasing next part but has nothing...