Skip to content

Attaching 'data' listeners immediately #1011

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

Open
mxschmitt opened this issue May 16, 2025 · 2 comments
Open

Attaching 'data' listeners immediately #1011

mxschmitt opened this issue May 16, 2025 · 2 comments
Labels

Comments

@mxschmitt
Copy link

mxschmitt commented May 16, 2025

Support plan

  • Which support plan is this issue covered by? (Community, Sponsor, Enterprise): Community
  • Currently blocking your project/work? (yes/no): yes
  • Affecting a production system? (yes/no): OSS - we can't update to formidable v3

Context

  • Node.js version: 22
  • Release Line of Formidable (Legacy, Current, Next): Current
  • Formidable exact version: v3
  • Environment (node, browser, native, OS): Node.js/macOS
  • Used with (popular names of modules):

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

In formidable v2/v3 the parsing is async and the 'data' handlers are attached not directly. This causes an issue that if you have multiple async things happening after the request was started other consumers might consume the buffered 'data' chunks. Then formidable is not able to parse the request anymore since it receives only a part of it.

An easy fix for that would be to attach the handlers earlier - at the beginning when calling parse.

Currently they are attached after writeHeaders:

await this.writeHeaders(req.headers);

See microsoft/playwright#35823 (comment) for more information. We would appreciate if this could considered since it breaks our use-case and potentially also other customers with async/await hops.

What was the result you got?

When there is an async hop which is consuming 'data' as well, formidable is not able to parse the request body.

What result did you expect?

It works like in formidable v1 - there the parsing was sync.

@tunnckoCore
Copy link
Member

tunnckoCore commented May 25, 2025

It's actually happening below that line.

I'll check the ticket in your repo too.

Anyway, please try the next dist-tag, a lot of the stuff around streaming is tricky and especially with events it sucks, so that's cleaned up. It uses async iterators and for of.

Plesse try the v4 (the next dist-tag, it's in monorepo branch), i don't want to bother anymore with that shitty useless layer (a Formidable EventEmitter class) that's sitting on top of the actual parser.

The parsing wasn't async, nor sync. And isn't now. The buggy layer on top of the core parser is what's causing all the issues and weirdnesses. The parse method just got async in some version. In fact it always was async, just with callbacks back in the days.

It's not the v3 that's the problem, but something else, because we were always async, and we were always reading data events from req at that same place.

@tunnckoCore
Copy link
Member

responded there too 🙌

@mxschmitt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants