node.js简单res.render超时

时间:2015-02-08 23:20:18

标签: node.js express amazon-ec2

我们有一个非常简单的node.js / express 4.0应用程序,目前包含一个默认路由:

/* GET home page */
router.get('/', function(req, res) {
  var products = heelsProducts;
  res.products = products;
  res.render('index', {title: 'Shop SKINNYprice!', req: req, products: res.products, _csrf: req.csrfToken()});
});

当我们在本地开发机器(Fedora 19)上访问它并且发出像$ curl http://localhost:3000之类的快速测试时,这条路线运行正常,导致索引页面html立即返回。

但是,当我们将此代码库部署到我们的AWS EC2实例(默认Linux AMI)并发出相同的卷曲时,该过程将在返回此错误之前挂起大约60秒:

Error: Can't set headers after they are sent.
    at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:335:11)
    at ServerResponse.header (/root/git/skinnypriceshop/code/shop/node_modules/express/lib/response.js:662:10)
    at ServerResponse.send (/root/git/skinnypriceshop/code/shop/node_modules/express/lib/response.js:146:12)
    at fn (/root/git/skinnypriceshop/code/shop/node_modules/express/lib/response.js:896:10)
    at /root/git/skinnypriceshop/code/shop/node_modules/ejs-locals/index.js:134:7
    at Object.exports.renderFile (/root/git/skinnypriceshop/code/shop/node_modules/ejs-locals/node_modules/ejs/lib/ejs.js:318:3)
    at module.exports (/root/git/skinnypriceshop/code/shop/node_modules/ejs-locals/index.js:85:7)
    at /root/git/skinnypriceshop/code/shop/node_modules/ejs-locals/index.js:131:7
    at Object.exports.renderFile (/root/git/skinnypriceshop/code/shop/node_modules/ejs-locals/node_modules/ejs/lib/ejs.js:318:3)
    at View.module.exports [as engine] (/root/git/skinnypriceshop/code/shop/node_modules/ejs-locals/index.js:85:7)

某些在线搜索此问题似乎表明某些后续响应正在尝试写入标题但是我们在代码中看到的任何内容似乎都不是这样的候选者。

此时的任何想法都将受到赞赏。

1 个答案:

答案 0 :(得分:0)

将此问题标记为已回答。对于yzarubin的评论,他最终引导我解决了服务器(memcached)上的一个中间件未启动的问题。