【发布时间】:2015-12-20 00:22:35
【问题描述】:
在 Express 中,我有一个路由可以对 Amazon S3 进行 http 调用,以查看特定图像是否存在(它基本上是一个代理调用,可以绕过我无法从浏览器直接向 Amazon 进行跨域调用) .
问题是它连续工作了一段时间,然后突然停止,只能通过我重新启动我的快速应用程序来解决。
以防万一(尽管我相信代码是完全通用的)代码如下:
Router.get('/testS3Image',
function(request, response){
try{
var imagePath = request.param('imagePath');
var https = require('https');
var options = {
method:'GET',
host: 's3.amazonaws.com',
path: '/' + imagePath,
port: 443
};
console.log("MAKING S3 call with options " + JSON.stringify(options));
var req = https.request(options,
function(res) {
try{
if(!res || !res.headers || !res.headers["content-length"])
throw ("image not found on S3");
console.log("returned from S3 call with success");
response.json({success:true,headers:res.headers});
}catch(e){
console.log("returned from S3 call with failure");
response.json({success:false, error:e});
}
}
);
req.end();
}catch(e){
}
});
在拨打https.request() 之后,什么也没有发生。它只是变暗。我对 Node 还很陌生,不知道如何才能了解幕后发生的事情。我们在 nginx 中运行它。
由于它可以完美运行很长时间,然后突然中断,没有明显的韵律或原因,我怀疑某种 http 调用限制,但我不清楚我可以做些什么不同的事情。
【问题讨论】:
-
您可以拍摄一些堆快照,看看是否可以看到任何可能无意累积的特别内容。
标签: node.js express nginx https