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

async json parsing #384

Closed
adrukh opened this issue Nov 16, 2019 · 1 comment
Closed

async json parsing #384

adrukh opened this issue Nov 16, 2019 · 1 comment

Comments

@adrukh
Copy link

adrukh commented Nov 16, 2019

Opening this issue to discuss an idea for an improvement that would help a specific use case we are having, and get the maintainers' feedback for it.

Problem

JSON.parse is synchronous, and blocks the event loop while parsing the raw data and creating a JS object with the parsed data. This makes HTTP services DoS-able to large request bodies, and the only solution right now is setting options.limit to protect oneself.

Proposed solution

With a plethora of JSON streaming libraries, one can implement parsing logic that would include setImmediate every now and then to yield the event loop during parsing.

Pros

  • JSON body parsing doesn't block the event loop for the entire duration of the process, and allows the event loop to handle other tasks.

Cons

  • Parsing becomes longer and more resource-consuming (yielding the event loop isn't cost-free)
  • Middleware becomes async in this case, will be a breaking change to current use-cases.

I'd appreciate feedback on this idea, it must have been proposed and discussed in the past. I found some prior art here - nodejs/node-v0.x-archive#7543, but that's a wider discussion.

Any 👍 or 👎 would be appreciated. I'm seeking wisdom that would help me to try this direction by myself, or perhaps even to find a way to contribute a relevant improvement to this wonderful package.

@dougwilson
Copy link
Contributor

Duplicate of #132

Please have the discussion on async json parsing in the above issue to keep it consolidated. It also has prior comments that might help answer questions you have as well.

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

No branches or pull requests

2 participants