Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IncomingForm end event emitted twice (at least) #810

Closed
dresende opened this issue Jan 6, 2022 · 14 comments
Closed

IncomingForm end event emitted twice (at least) #810

dresende opened this issue Jan 6, 2022 · 14 comments
Labels
Priority: High After critical issues are fixed, these should be dealt with before any further issues. Status: Accepted It's clear what the subject of the issue is about, and what the resolution should be. Type: Bug Inconsistencies or issues which will cause an issue or problem for users or implementors.

Comments

@dresende
Copy link

dresende commented Jan 6, 2022

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.

@dresende dresende added the bug label Jan 6, 2022
@GrosSacASac
Copy link
Contributor

I 'll have a look

@tunnckoCore
Copy link
Member

tunnckoCore commented Jan 7, 2022

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
Copy link
Author

dresende commented Jan 7, 2022

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
Copy link
Author

dresende commented Jan 7, 2022

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

@tunnckoCore
Copy link
Member

Thanks for testing.

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

@LatenC
Copy link

LatenC commented Jan 19, 2022

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

@Fedacc
Copy link

Fedacc commented Mar 31, 2022

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

@tunnckoCore tunnckoCore added area: networking Priority: High After critical issues are fixed, these should be dealt with before any further issues. Status: Accepted It's clear what the subject of the issue is about, and what the resolution should be. Type: Bug Inconsistencies or issues which will cause an issue or problem for users or implementors. and removed area: networking labels Mar 31, 2022
@GrosSacASac
Copy link
Contributor

Published as 3.2.3

@marcorocci
Copy link

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
Copy link
Contributor

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

@dresende
Copy link
Author

so once instead of on

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

@wbt
Copy link
Collaborator

wbt commented Aug 11, 2022

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
Copy link
Author

Just about nothing is "obvious" to everybody.

That's obvious or a paradox? 😂

@julientype
Copy link

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: High After critical issues are fixed, these should be dealt with before any further issues. Status: Accepted It's clear what the subject of the issue is about, and what the resolution should be. Type: Bug Inconsistencies or issues which will cause an issue or problem for users or implementors.
Projects
None yet
Development

No branches or pull requests

8 participants