1

将我的应用程序从 IntoVPS 迁移到 Digital Ocean 后,我的应用程序在尝试将照片上传到 AWS S3 时崩溃。

服务器之间的区别是:IntoVPS 运行的是 Ubuntu 10.10,而 Digital Ocean 运行的是 Debian;IntoVPS 有节点 0.8.x,Digital Ocean 有 0.10.26。

新服务器上没有可能导致此问题的防火墙(我已经检查过)。

崩溃错误是:

Error: read ECONNRESET
  at errnoException (net.js:904:11)
  at Pipe.onread (net.js:558:19)

Error: spawn ENOENT
  at errnoException (child_process.js:988:11)
  at Process.ChildProcess._handle.onexit (child_process.js:779:34)

Error: write EPIPE
  at errnoException (net.js:904:11)
  at Object.afterWrite (net.js:720:19)

其中一些可能与永远试图重新启动进程有关(我认为这就是 spawn 的含义)。我要关注的是 ECONNRESET 之一。

所以,我正在使用永远运行我的进程,并且我正在使用 knox 模块连接到 S3。

谷歌搜索后我发现:https ://github.com/LearnBoost/knox/issues/198

我尝试添加它在中所说res.resume()的回调,但没有任何变化;putFile我仍然收到 ECONNRESET 错误。

我花了一整天(昨天)试图解决这个问题,但我不能继续让我的生产应用程序被破坏,所以我决定尝试切换到旧版本的 Node 以暂时(但快速)修复这个问题。因此,我安装了 n 模块以尝试获取 0.8.26 作为安装的节点版本。不幸的是,n 没有用,这是我创建的问题:https ://github.com/visionmedia/n/issues/170

编辑:

退出我的 ssh 会话并打开一个新会话后,n 正在工作。但是,切换到 0.8.26 版本的节点会导致另一个错误:

/apps/Foobar/node_modules/dnode/node_modules/weak/node_modules/bindings/bindings.js:83
        throw e
              ^
Error: Module version mismatch, refusing to load.
  at Object.Module._extensions..node (module.js:485:11)
  at Module.load (module.js:356:32)
  at Function.Module._load (module.js:312:12)
  at Module.require (module.js:362:17)
  at require (module.js:378:17)
  at bindings (/apps/Foobar/node_modules/dnode/node_modules/weak/node_modules/bindings/bindings.js:76:44)
  at Object.<anonymous> (/apps/Foobar/node_modules/dnode/node_modules/weak/lib/weak.js:1:97)
  at Module._compile (module.js:449:26)
  at Object.Module._extensions..js (module.js:467:10)
  at Module.load (module.js:356:32)
  at Function.Module._load (module.js:312:12)
  at Module.require (module.js:362:17)
  at require (module.js:378:17)
  at Object.<anonymous> (/apps/Foobar/node_modules/dnode/index.js:5:12)
  at Module._compile (module.js:449:26)
  at Object.Module._extensions..js (module.js:467:10)
  at Module.load (module.js:356:32)
  at Function.Module._load (module.js:312:12)
  at Module.require (module.js:362:17)
  at require (module.js:378:17)
  at Object.<anonymous> (/apps/Foobar/controllers/sock.js:2:13)
  at Module._compile (module.js:449:26)
  at Object.Module._extensions..js (module.js:467:10)
  at Module.load (module.js:356:32)
  at Function.Module._load (module.js:312:12)
  at Module.require (module.js:362:17)
  at require (module.js:378:17)
  at global.Controller (/apps/Foobar/globals.js:2:9)
  at Object.<anonymous> (/apps/Foobar/controllers/generosity.js:209:12)
  at Module._compile (module.js:449:26)
  at Object.Module._extensions..js (module.js:467:10)
  at Module.load (module.js:356:32)
  at Function.Module._load (module.js:312:12)
  at Module.require (module.js:362:17)
  at require (module.js:378:17)
  at global.Controller (/apps/Foobar/globals.js:2:9)
  at Object.<anonymous> (/apps/Foobar/app.js:282:1)
  at Module._compile (module.js:449:26)
  at Object.Module._extensions..js (module.js:467:10)
  at Module.load (module.js:356:32)
  at Function.Module._load (module.js:312:12)
  at Module.runMain (module.js:492:10)
  at process.startup.processNextTick.process._tickCallback (node.js:245:9)

正如你所看到的,我正在尝试用 S3 解决这个问题,而且我快哭了(隐喻地)。我不能一直在这个问题上浪费时间,但我似乎无法解决它。几乎就像 Node 本身坏了一样。

任何人都可以提供有关发生了什么的任何见解吗?对此的任何帮助表示赞赏。

为什么诺克斯不再工作了?

编辑

这里有更多细节。

错误代码:

// S3
var endpoint = "https://s3.amazonaws.com/"+global.config.aws.s3.bucket+"/";
var knox = require('knox');
var s3 = knox.createClient(global.config.aws.s3);
var photosPrefix = 'photos/';


var model = module.exports;

model.emitter = new events.EventEmitter;


// ::Photos
model.createPhoto = function(info, cb){
    if (!info.file || path.resolve(info.file) === path.resolve(global.__tempdir))
        return cb(new Error('missing info.file'));

    var db = info.db;
    var photoId;

    if (typeof info.public === 'undefined')
        info.public = false;

    // Move file to a specific location
    var basename = path.basename(info.file);
    var destination = photosPrefix+basename+'/original';

    yarn
    (function(){
        // Upload photo to AWS
        s3.putFile(
            info.file, 
            destination, 
            {
                'Content-Type': 'image/png'
            },
            this());
    })
    (function(err, res){
        if (err) return this.error(new Error(err));

        // Remove temporary file
        fs.unlink(info.file, this());
    })
    (function(err){
        if (err) return this.error(new Error(err));

        // Retrieve photo stream from AWS
        s3.getFile(destination, this());
    })
    (function(err, res){
        if (err) return this.error(new Error(err));

        // Get the dimensions of the photo using the stream (res)
        gm(res).size(this());
    })
    (function(err, size){
        if (err) return this.error(new Error(err));

        // Insert record into photos table (include the dimensions, width and height)
        db.query("INSERT photos (resource, width, height, public) VALUES (?, ?, ?, ?)", [basename, size.width, size.height, info.public], this());
    })
    (function(err, results){
        if (err) return this.error(new Error(err));

        photoId = results.insertId;

        cb(null, photoId);
    })
    .error(function(err){
        cb(err);
    });
}

所有照片无论大小或格式如何都会导致相同的错误。

4

1 回答 1

0

我发现问题不在于 AWS 和 knox,而在于 gm 以及我的系统上没有安装 GraphicsMagick 的事实。

作为其他人的参考,如果您遇到类似的错误,请记住 gm 不会在 GraphicsMagick 或 ImageMagick 不存在时报告它们不存在。我在 gm 模块上报告了这个错误:https ://github.com/aheckmann/gm/issues/273

于 2014-04-24T05:36:56.640 回答