h3 icon indicating copy to clipboard operation
h3 copied to clipboard

Handle large bodies

Open stafyniaksacha opened this issue 1 year ago • 2 comments

Environment

  • nuxt: 3.6.5
  • nitropack 2.5.2
  • h3: 1.8.0
  • listhen: 1.3.0

Reproduction

  • https://stackblitz.com/edit/nuxt-starter-hbwprt?file=app.vue,server%2Fapi%2Fupload.ts,server%2Fapi%2Fupload-formidable.ts
  • https://github.com/stafyniaksacha/nuxt-upload-reproduction

it seems that stackblitz apply restriction on some file upload

Describe the bug

When using readMultipartFormData from h3, request is written in a memory buffer, this result in OOM crash if uploaded file is greater than available memory max-old-space-size.

A solution would be to pipe the incoming data stream into a temp file, like formidable or busboy does. Those libraries allow checking uploaded file size too, to prevent uploading large file.

The issue I have using those libraries is that it's impossible to write to the response after they have thrown (ex: send 413 Content Too Large error).

Additional context

  • #103

Logs

Uploading a zip file >1Gb (with readMultipartFormData) error:

#
# Fatal error in , line 0
# Fatal JavaScript invalid size error 169220804
#
#
#FailureMessage Object: 0x7f82a74fb230
 1: 0xbe70f1  [/home/stf/.nvm/versions/node/v18.15.0/bin/node]
 2: 0x1e4af64 V8_Fatal(char const*, ...) [/home/stf/.nvm/versions/node/v18.15.0/bin/node]
 3: 0xf0c8c8  [/home/stf/.nvm/versions/node/v18.15.0/bin/node]
 4: 0x10bbd92  [/home/stf/.nvm/versions/node/v18.15.0/bin/node]
 5: 0x10bc052  [/home/stf/.nvm/versions/node/v18.15.0/bin/node]
 6: 0x12cb06b v8::internal::Runtime_GrowArrayElements(int, unsigned long*, v8::internal::Isolate*) [/home/stf/.nvm/versions/node/v18.15.0/bin/node]
 7: 0x1707b79  [/home/stf/.nvm/versions/node/v18.15.0/bin/node]

Note that it sometime throw ERROR [h3] write EPIPE

stafyniaksacha avatar Aug 21 '23 14:08 stafyniaksacha