Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

clean-up open filehandles and files on error

  • Loading branch information...
commit 56655355a47f06ff002de5c143e6cda1a40a6a98 1 parent 31c2c3f
@OrangeDog OrangeDog authored
Showing with 7 additions and 0 deletions.
  1. +7 −0 lib/incoming_form.js
View
7 lib/incoming_form.js
@@ -89,6 +89,7 @@ IncomingForm.prototype.parse = function(req, cb) {
};
this.writeHeaders(req.headers);
+ this.openedFiles = [];
var self = this;
req
@@ -204,6 +205,7 @@ IncomingForm.prototype.handlePart = function(part) {
this.emit('fileBegin', part.name, file);
file.open();
+ this.openedFiles.push(file);
part.on('data', function(buffer) {
self.pause();
@@ -253,6 +255,11 @@ IncomingForm.prototype._error = function(err) {
this.error = err;
this.pause();
this.emit('error', err);
+
+ this.openedFiles.forEach(function(file) {
+ file._writeStream.destroy();
+ setTimeout(fs.unlink, 0, file.path);
+ });
};
IncomingForm.prototype._parseContentLength = function() {
Please sign in to comment.
Something went wrong with that request. Please try again.