sails: Aborted upload crashes the server
Adapter: skipper-gridfs Basic controller code:
req.file('fileTest')
.upload({
// You can apply a file upload limit (in bytes)
maxBytes: maxUpload,
adapter: require('skipper-gridfs'),
uri: bucketConnect,
saveAs : function (__newFileStream,cb) {
cb(null, __newFileStream.filename);
}
}, function whenDone(err, uploadedFiles) {
if (err) {
var error = { "status": 500, "error" : err };
return res.serverError(error);
}else {
I have a jQuery-File-Upload client ( https://blueimp.github.io/jQuery-File-Upload/ ) impementing the “cancel” procedure by using jqXHR abort described here (https://github.com/blueimp/jQuery-File-Upload/wiki/API ):
$('button.cancel').click(function (e) {
jqXHR.abort();
});
After the client aborts, the server crashes with the following message:
events.js:72
throw er; // Unhandled 'error' event
^
Error: Request aborted
at IncomingMessage.onReqAborted (.../node_modules/sails/node_modules/skipper/node_modules/multiparty/index.js:175:17)
at IncomingMessage.EventEmitter.emit (events.js:92:17)
at abortIncoming (http.js:1911:11)
at Socket.serverSocketCloseListener (http.js:1923:5)
at Socket.EventEmitter.emit (events.js:117:20)
at TCP.close (net.js:466:12)
I’ve used try/catch but it didn’t work, the server crashes anyway.
I am not sure if this is a Skipper issue or a Multiparty issue – my knowledge stops here ( https://github.com/andrewrk/node-multiparty/blob/master/index.js ):
function onReqAborted() {
waitend = false;
self.emit('aborted');
handleError(new Error("Request aborted"));
}
function onReqEnd() {
waitend = false;
}
function handleError(err) {
var first = !self.error;
if (first) {
self.error = err;
req.removeListener('aborted', onReqAborted);
req.removeListener('end', onReqEnd);
if (self.destStream) {
self.destStream.emit('error', err);
}
}
cleanupOpenFiles(self);
if (first) {
self.emit('error', err);
}
}
Any clues?
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Comments: 56 (25 by maintainers)
Commits related to this issue
- Don't emit errors on incoming file streams more than once refs #49 — committed to sailshq/skipper by sgress454 8 years ago
- Added boolean to avoid multiple errors https://github.com/balderdashy/skipper/issues/49 Adapter is emitting multiple errors on aborted upload. After the first one is emitted, the underlying skipper ... — committed to cburatto/skipper-gridfs by cburatto 8 years ago
- Use ".on()" instead of ".once()" to handle stream errors. Multiple errors on a stream will be handled gracefully by `fatalIncomingError`. refs https://github.com/balderdashy/skipper/issues/49 — committed to sailshq/skipper by sgress454 8 years ago
@OwaysisApp +1, you have the same problem? +1, the updated code solves your problem? +1, you agree with @cburatto that I’m great? (appreciated, but not immensely helpful).
FYI the easiest way to test the updated code in your app is:
and then in config/http.js:
It’s important that the bodyParser property be at the top level (module.exports.http), and not under the “middleware” property.