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

时间:2013-09-30 07:24:32

标签: node.js express amazon-s3 knox-amazon-s3-client

我在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)

启用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();
};

如何处理错误,使服务器不会崩溃?

1 个答案:

答案 0 :(得分:0)

您很可能忘记在服务器套接字的'error'事件中添加处理程序。

堆栈不包含对代码的任何引用的原因是由于node.js的偶然性质。每当事件触发时,堆栈将从头开始重新启动。因此,调试异步调用有点困难。

您可以在开发过程中尝试使用longjohn