中止上传导致Sails js / Skipper崩溃 [英] Aborted upload causes Sails js/Skipper to crash

查看:224
本文介绍了中止上传导致Sails js / Skipper崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

参考: https://github.com/balderdashy/skipper/issues/49 b
$ b

适配器:skipper-gridfs

基本控制器代码:

  req.file('fileTest')
.upload({

//您可以应用文件上传限制)
maxBytes:maxUpload,
adapter:require('skipper-gridfs'),
uri:bucketConnect,
saveAs:function(__newFileStream,cb){
cb (null,__newFileStream.filename);
}

},函数whenDone(err,uploadedFiles){
if(err){
var error = {status :500,error:err};
return res.serverError(error);
} else {

我有一个jQuery文件上传客户端( https:/ /blueimp.github.io/jQuery-File-Upl oad / )通过使用这里描述的jqXHR中止来阻止取消过程( https://github.com/blueimp/jQuery-File-Upload/wiki/API ):

  $('button.cancel')。click(function(e){
jqXHR.abort();
});

客户端中止后,服务器崩溃并显示以下消息:

  events.js:72 
throw er; //未处理的错误事件
$
错误:请求中止
IncomingMessage.onReqAborted(... / node_modules / sails / node_modules / skipper / node_modules / multiparty / index.js:175 :17)
在IncomingMessage.EventEmitter.emit(events.js:92:17)
at abortIncoming(http.js:1911:11)
在Socket.serverSocketCloseListener(http.js: 1923:5)
在Socket.EventEmitter.emit(events.js:117:20)
at TCP.close(net.js:466:12)

我使用了try / catch,但是没有成功,服务器崩溃了。

我不确定这是一个船长问题还是一个多方问题 - 我的知识在这里停止( https://github.com/andrewrk/node-multiparty/blob/master/index.js ):

 函数onReqAborted(){
waitend = false;
self.emit('aborted');
handleError(new Error(Request aborted));
}

函数onReqEnd(){
waitend = false;
}

函数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);


$ / code $ / pre

起初我以为这是jqXHR请求被中止,但它似乎是一个普通的Skipper问题,因为在上传过程中关闭标签的简单行为会导致服务器崩溃(不同的消息):

  _stream_writable.js:233 
cb(er);

TypeError:对象不是函数
onwriteError(_stream_writable.js:233:5)
onwrite(_stream_writable.js:253:5)
在WritableState.onwrite(_stream_writable.js:97:5)
在Writable。< anonymous> (... / node_modules / skipper-gridfs / index.js:179:25)
在Writable.g(events.js:180:16)
在Writable.EventEmitter.emit(events.js :117:20)PassThrough
< anonymous> (... / node_modules / skipper-gridfs / index.js:194:36)
在PassThrough.g(events.js:180:16)
在PassThrough.EventEmitter.emit(events.js :117:20)
at ... / node_modules / sails / node_modules / skipper / standalone / Upstream / prototype.fatalIncomingError.js:55:17

我已经尝试使用简单的上传控制器(不是Skipper)关闭标签来中止上传,并且没有崩溃:

  var uploadFile = req.file('fileTest'); 
console.log(uploadFile);如果(err)return res.serverError(err)

$ uploadFile.upload(function onUploadComplete(err,files){//文件将被上传到.tmp / uploads

; // IF ERROR返回并发送500错误,错误

console.log(files);
res.json({status:200,file:files});
});

所以,有没有人看到这种情况,有什么解决方法?

解决方案

skipper@0.5.4和skipper-disk@0.5.4已经解决了这个问题。



参考: https://github.com/balderdashy/skipper/issues/49

Ref: https://github.com/balderdashy/skipper/issues/49

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);
    }
  }

At first I thought this was the way the jqXHR request was aborted, but it seems to be a generic Skipper issue on aborted uploads, since the simple act of closing the tab during an upload will crash the server (different message):

_stream_writable.js:233
    cb(er);
    ^
TypeError: object is not a function
    at onwriteError (_stream_writable.js:233:5)
    at onwrite (_stream_writable.js:253:5)
    at WritableState.onwrite (_stream_writable.js:97:5)
    at Writable.<anonymous> (.../node_modules/skipper-gridfs/index.js:179:25)
    at Writable.g (events.js:180:16)
    at Writable.EventEmitter.emit (events.js:117:20)
    at PassThrough.<anonymous> (.../node_modules/skipper-gridfs/index.js:194:36)
    at PassThrough.g (events.js:180:16)
    at PassThrough.EventEmitter.emit (events.js:117:20)
    at .../node_modules/sails/node_modules/skipper/standalone/Upstream/prototype.fatalIncomingError.js:55:17

I have tried aborting the upload by closing the tab while using a simple upload controller (not Skipper) and there is no crash:

var uploadFile = req.file('fileTest');
    console.log(uploadFile);

    uploadFile.upload(function onUploadComplete (err, files) {                // Files will be uploaded to .tmp/uploads

        if (err) return res.serverError(err);                              // IF ERROR Return and send 500 error with error

        console.log(files);
        res.json({status:200,file:files});
    });

So, did anybody see this happening and is there any workaround?

解决方案

This issue has been solved in skipper@0.5.4 and skipper-disk@0.5.4

Ref.: https://github.com/balderdashy/skipper/issues/49

这篇关于中止上传导致Sails js / Skipper崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆