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

Crash when aborting a file too soon #469

Closed
quantumsheep opened this issue Jun 17, 2018 · 4 comments
Closed

Crash when aborting a file too soon #469

quantumsheep opened this issue Jun 17, 2018 · 4 comments

Comments

@quantumsheep
Copy link
Collaborator

Aborting an upload too soon make the server crash.
Here's the throwed error:

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.write (fs.js:2282:5)
    at FSReqWrap.wrapper [as oncomplete] (fs.js:643: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:643:5)

No stacktrace, no fun

It appears to be from the file's write stream
Using the onPart event may resolve the issue but that's not the goal.

@quantumsheep
Copy link
Collaborator Author

#316 fix the error

@xarguments
Copy link
Collaborator

Is the same error as in this issue. They seem to be related.

@quantumsheep
Copy link
Collaborator Author

@xarguments seems like the same! You're very active, that's really nice 😄

@lenolib
Copy link

lenolib commented Jun 25, 2019

For others who need a quick fix for preventing the server from crashing:

  const form = new IncomingForm();
  form.onPart = part => {
    form.handlePart(part);
    if (part.filename !== undefined) {
      form.openedFiles[form.openedFiles.length - 1]._writeStream.on('error', err => {
        form.emit('error', err);
      });
    }
  };

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.

5 participants