IncomingForm end event emitted twice (at least)
dresende opened this issue ยท 14 comments
Support plan
- Which support plan is this issue covered by? Community
- Currently blocking your project/work? no
- Affecting a production system? yes
Context
- Node.js version: v14 and v16 at least
- Release Line of Formidable: Current
- Formidable exact version: 2.0.1 (npm)
- Environment: node, macOS and Linux, does not matter
- Used with (popular names of modules): express
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.
I 'll have a look
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.
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.
Just tested with only 1 field and it still emits 2 events. And... this only occurs for form-data
body type.
Thanks for testing.
Hm, yea.. definitely strange. We should look and follow the whole flow more carefully .
Same issue happened with me also.
I am also using the same version - 2.0.1
I see the same issue also on version 2.0.0
, event 'end' is emitted twice regardless of the number of files/fields received
Published as 3.2.3
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
@marcorocci true but the library should also not emit end twice to begin with
so once instead of on
That's obvious and that's how people worked around it until it is/was fixed.
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.
Just about nothing is "obvious" to everybody.
That's obvious or a paradox? ๐
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...