【问题标题】:Node.js crashing when connecting to AWS S3连接到 AWS S3 时 Node.js 崩溃
【发布时间】:2014-06-08 23:41:56
【问题描述】:

将我的应用程序从 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 版本的 node 会导致另一个错误:

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

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

【问题讨论】:

  • 关于您更新的问题-也许是“我当然做了”的问题,但是您是否清除了 node_modules 然后在降级节点后重新安装?猜测是 0.8.x 和 0.10.x 之间的重大更改正在影响您拥有的模块。另外,我不知道 npm 是否足够聪明,可以根据模块的“引擎”(无论如何可能并不总是有用)安装正确的旧版本,或者您是否需要手动指定版本。我自己还没有机会降级。在这种情况下,也许有人可以确认 npm 行为。文档没有说明我可以看到。

标签: node.js amazon-s3 debian digital-ocean knox-amazon-s3-client


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-18
    • 2020-05-17
    • 2020-02-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多