You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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.
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 settingoptions.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
Cons
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.
The text was updated successfully, but these errors were encountered: