简体   繁体   English

Knox S3-NodeJS / ExpressJS错误:套接字挂起

[英]Knox S3 - NodeJS/ExpressJS Error: socket hang up

I encountered the error below with NodeJS module for Amazon S3: Knox 我在使用Amazon S3的NodeJS模块时遇到以下错误: Knox

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: socket hang up
    at SecurePair.error (tls.js:934:23)
    at CleartextStream.read [as _read] (tls.js:432:17)
    at CleartextStream.Readable.read (_stream_readable.js:320:10)
    at EncryptedStream.write [as _write] (tls.js:345:25)
    at doWrite (_stream_writable.js:219:10)
    at writeOrBuffer (_stream_writable.js:209:5)
    at EncryptedStream.Writable.write (_stream_writable.js:180:11)
    at write (_stream_readable.js:573:24)
    at flow (_stream_readable.js:582:7)
    at Socket.pipeOnReadable (_stream_readable.js:614:5)
    at Socket.EventEmitter.emit (events.js:92:17)

After enabling longjohn , I can say that the error is on route for display image from Amazon S3. 启用longjohn ,我可以说该错误来自Amazon S3的显示图像。

exports.image = function(req, res) {
    var type = req.params.type;
    var id = req.params.id;
    var file = req.params.file;
    var url = '/' + type + '/' + id + '/' + file;


    var data = '';
    knoxClient.get(url).on('response', function(s3res) {
        s3res.setEncoding('binary');
        s3res.on('data', function(chunk){
            data += chunk;
        });
        s3res.on('end', function() {
            res.write(data, encoding='binary');
            res.end();
        });
    }).end();
};

How to handle the error such that the server will not crash ? 如何处理错误,使服务器不会崩溃?

You most likely forgot to add a handler to the 'error' event of your server socket. 您最有可能忘记为服务器套接字的'error'事件添加处理程序。

The reason why the stack does not contain any reference to your code is because of the evented nature of node.js. 堆栈不包含对代码的任何引用的原因是由于node.js的事件性质。 Whenever an event fires, the stack is restarted from scratch. 每当事件触发时,都会从头开始重新启动堆栈。 Because of this, it's a bit hard to debug async calls. 因此,调试异步调用有点困难。

You can try using longjohn during development. 您可以在开发期间尝试使用longjohn

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM