Looks like there are two pieces in play here, the maxBodySize doesn't limit the upload, rather it limits the body size regardless of how much data is uploaded. The second piece is running out of memory due to Node reading in the file.
Restify could abort the request and return a HTTP 413 status code in that case. @yunong or @DonutEspresso what are your thoughts?
Hey @rkarami! It doesn't look like there currently is a way to effectively limit the upload size at the front door. If you are interested in taking a pass at a PR I would be happy to offer help!
@micahr, @retrohacker, and @yunong FWIW I have only been able to reproduce this on Restify versions <= 2.x.x. It seems like the current code for the body reader reads in chunks until it is done or when a given chunk exceeds maxBodySize, which seems effective but it's possible I'm missing something.
I tested with different Node versions (0.10.48, 4.8.5, 6.14.3) and different Restify versions (2.0.0, 3.0.0, 4.0.0, 4.3.3). I used the exact code listed in this issue and an 8GB file uploaded from a separate machine to the test application. Only restify 2.0.0 hit ENOMEM and ENOSPC.
The bodyParser middleware seems to buffer the whole file in memory for file uploads.
Check the following minimum example:
Then, upload a really big file to it:
This will send the process into accumulating tons of memory until it eventually runs out of memory and crashes with:
Am I making a mistake in setting up the middleware or is this a bug?
The text was updated successfully, but these errors were encountered: