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

Return the transmission when the large file is uploaded #470

Closed
MunMunMiao opened this issue Jun 18, 2018 · 20 comments
Closed

Return the transmission when the large file is uploaded #470

MunMunMiao opened this issue Jun 18, 2018 · 20 comments

Comments

@MunMunMiao
Copy link

  Error: Request aborted
      at IncomingMessage.<anonymous> (/web/elris/Server/node_modules/formidable/lib/incoming_form.js:122:19)
      at IncomingMessage.emit (events.js:182:13)
      at abortIncoming (_http_server.js:444:9)
      at socketOnClose (_http_server.js:437:3)
      at Socket.emit (events.js:187:15)
      at TCP._handle.close [as _onclose] (net.js:595:12)

events.js:167
      throw er; // Unhandled 'error' event
      ^

Error [ERR_STREAM_DESTROYED]: Cannot call write after a stream was destroyed
    at doWrite (_stream_writable.js:406:19)
    at clearBuffer (_stream_writable.js:540:7)
    at onwrite (_stream_writable.js:465:7)
    at fs.js:2329:5
    at FSReqWrap.wrapper [as oncomplete] (fs.js:2295:5)
Emitted 'error' event at:
    at onwriteError (_stream_writable.js:425:12)
    at onwrite (_stream_writable.js:456:5)
    at doWrite (_stream_writable.js:406:11)
    at clearBuffer (_stream_writable.js:540:7)
    [... lines matching original stack trace ...]
    at FSReqWrap.wrapper [as oncomplete] (fs.js:2295:5)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! lovelyz@1.0.0 dev: `node ./app/index.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the lovelyz@1.0.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/miaomunmun/.npm/_logs/2018-06-18T12_34_00_801Z-debug.log

@xarguments
Copy link
Collaborator

Could you please provide more info?

@MunMunMiao
Copy link
Author

@xarguments When uploading more than 500kb files, Request aborted will appear.

@tunnckoCore
Copy link
Member

tunnckoCore commented Jun 24, 2018

Sounds pretty familiar - https://github.com/tunnckoCore/koa-better-body/issues/109.
But you said 500kb, not 500mb. Anyway.

The default maxFileSize was bumped to 200mb in v1.2.1?
Try adding maxFileSize option manually?

@MunMunMiao
Copy link
Author

this's my config

 app.use(koaBody({
        encoding: 'utf-8',
        urlencoded: false,
        text: true,
        json: true,
        strict: false,
        jsonLimit: 0,
        formLimit: 0,
        textLimit: 0,
        multipart: true,
        formidable: {
            uploadDir: global.userConfig.path.tmp,
            keepExtensions: false,
            maxFileSize: 10 * 1024 *1024 * 1024,
            maxFields: 0,
            hash: false,
            multiples: true
        }
    }))

@MunMunMiao
Copy link
Author

More than 500kb will be wrong

@xarguments
Copy link
Collaborator

Though I'm not familiar with koa-body, but there text: true, json: true... Perhaps it tries to accept as text/JSON? If its the case then it surely will fail...

@MunMunMiao, few more questions:

  1. Does it happen when multiples: false?
  2. Which version of KoaBody/Formidable/NodeJS you use?

(@olstenlarck AFAIK you are better at koa-body, maybe you can take a better look at it?)

@MunMunMiao
Copy link
Author

@xarguments I tried it, not that problem

node v10.4.1
koa-body v4.0.3
formidable v1.2.1

@tunnckoCore
Copy link
Member

Koa-body was written by me from scratch, so yea. And it only uses formidable when multipart:true.

@tunnckoCore
Copy link
Member

@MunMunMiao, can you try koa-better-body? It was there before koa-body I believe.

I definitely dont see why this happen. It not make sense.

@alifarahmandnejad
Copy link

same here.
after canceling upload process from client, it's happened.

@xarguments
Copy link
Collaborator

@MunMunMiao is there something standing between your front-end and backend?
I remember there was similar issue when NginX was "dropping" requests with big bodies, like when uploading 1MB file. Increasing NginX limit from config client_max_body_size 512M; solved the issue

@xarguments
Copy link
Collaborator

Hi @alifarahmandnejad,
Tried to reproduce, with multiples:true - uploaded 2 files (~2GB each) at once in one request and aborted in the middle, but couldn't reproduce.
The error successfully gets caught in form.on('error', ...) (which is good), and I don't receive the further long errors that @MunMunMiao mentioned above (Error [ERR_STREAM_DESTROYED]...).

Could you please provide some code or case? (Help us to help you ;)).
And/or answer the questions below:

  1. Does it happen when uploading one file?
  2. Or perhaps happens when uploading multiple files simultaneously?
  3. Or perhaps happens when uploading multiple files in one request, with config multiples: true?

Thanks.


I guess the issue can be from incoming_form.js error handler. When error happens, it destroys the file streams - see lines marked with (1) and (2) below. And then, if somehow new data tries to get written to disk, it will fail with that error. So it is theoretically possible.

IncomingForm.prototype._error = function(err) {
  if (this.error || this.ended) {
    return;
  }

  this.error = err;
  this.emit('error', err);

  if (Array.isArray(this.openedFiles)) {
    this.openedFiles.forEach(function(file) {
      file._writeStream.destroy(); // (1)
      setTimeout(fs.unlink, 0, file.path, function(error) { }); // (2)
    });
  }
};

@xarguments xarguments added the bug label Feb 12, 2019
@MunMunMiao
Copy link
Author

I set the client_max_body_size of nginx to 512M, but the small file (<=2M) is normal, and it is not possible to be larger than 2M.

@alifarahmandnejad
Copy link

hi @xarguments
it's happened in just case 1.

info:
i commented this line of your code:
setTimeout(fs.unlink, 0, file.path, function(error) { }); // (2)

because i need uncompleted file to resume download from last byte in next upload try.

@tunnckoCore tunnckoCore reopened this Nov 22, 2019
tunnckoCore added a commit that referenced this issue Nov 28, 2019
thanks to #316 by @gabipetrovay, closes #469, possible fix #470 too

Co-authored-by: gabipetrovay
@tunnckoCore tunnckoCore unpinned this issue Jan 29, 2020
@chitkarian-19
Copy link

Error: Request aborted
at IncomingMessage. (C:\Users\ENV-08\Desktop\App\my-event-app\projbackend\node_modules\formidable\lib\incoming_form.js:122:19)
at IncomingMessage.emit (events.js:198:13)
at abortIncoming (_http_server.js:448:9)
at socketOnClose (_http_server.js:441:3)
at Socket.emit (events.js:203:15)
at TCP._handle.close (net.js:606:12) {} {}

This error is still coming even when i submit empty data on localhost server, Please help, I am not able to understand why form.parse() is not working

@tunnckoCore
Copy link
Member

@chitkarian-19 please open new issue with more info and versions.

@AmeerAsif777
Copy link

@tunnckoCore @chitkarian-19 I am also getting the same error.

FormidableError: Request aborted
at IncomingMessage. (C:\Users\App\server\node_modules\formidable\src\Formidable.js:197:21)
at IncomingMessage.emit (node:events:390:28)
at IncomingMessage._destroy (node:_http_incoming:179:10)
at _destroy (node:internal/streams/destroy:102:25)
at IncomingMessage.destroy (node:internal/streams/destroy:64:5)
at abortIncoming (node:_http_server:596:9)
at socketOnClose (node:_http_server:590:3)
at Socket.emit (node:events:402:35)
at TCP. (node:net:687:12) {
code: 1002,
httpCode: 500
}

@chitkarian-19
Copy link

@AmeerAsif777 are u passing multipart form data, I mean are u passing any image/video in the form request body ?

@laurent22
Copy link

This error doesn't seem to have been completely fixed. I'm getting the exact same crash in Formidable 3.5.1:

server_1  | 2023-10-29 10:08:51: [error] App: 174.194.132.166 FormidableError: Could not parse form: Request aborted
server_1  |     at IncomingMessage.<anonymous> (/home/joplin/packages/server/node_modules/formidable/dist/index.cjs:1223:21)
server_1  |     at IncomingMessage.emit (node:events:517:28)
server_1  |     at IncomingMessage._destroy (node:_http_incoming:224:10)
server_1  |     at _destroy (node:internal/streams/destroy:109:10)
server_1  |     at IncomingMessage.destroy (node:internal/streams/destroy:71:5)
server_1  |     at abortIncoming (node:_http_server:766:9)
server_1  |     at socketOnClose (node:_http_server:760:3)
server_1  |     at Socket.emit (node:events:529:35)
server_1  |     at TCP.<anonymous> (node:net:350:12) {
server_1  |   code: 1002,
server_1  |   httpCode: 500
server_1  | }
server_1  | Error: Cannot call write after a stream was destroyed
server_1  |     at new NodeError (node:internal/errors:405:5)
server_1  |     at node:internal/fs/streams:406:23
server_1  |     at FSReqCallback.wrapper [as oncomplete] (node:fs:829:5)
ubuntu_server_1 exited with code 1

I don't use koa-body. Any idea what the issue might be? Is there some error handled that I should listen to, to prevent my server from crashing?

This is the code I'm using:

https://github.com/laurent22/joplin/blob/49c1c9aa652aff50560ab5f46c9bcdfccbac6409/packages/server/src/utils/requestUtils.ts#L73

@laurent22
Copy link

By the way is it possible there's a regression in a recent Formidable version? We've used Formidable v1, then v2, for nearly two years without ever experiencing this bug, but since we've upgraded to 3.x it happened.

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

Successfully merging a pull request may close this issue.

7 participants