My question is similar to this question: Node Js:从 Node.js 服务器向某个 API 发送1000个HTTP GET请求是否可能,但是他们使用的限流解决方案对我不起作用。
我正在调用托管在 Google App Engine 上的我们的 API/网站来触发更新特定产品页面的内存缓存的任务。这个函数
updateCache
从一个async.eachSeries
中被调用。代码非常直观:(这是经过精简处理的版本)function updateCache(object_name, callback) {
var options = {
host : 'www.example.com',
path : '/update-cache/' + object_name,
method : 'GET',
agent : false,
};
var req = https.request(options, function(res) {
res.on('data', function() {
if (res.statusCode !== 200) {
console.log('successful');
}
});
res.on('end', function() {
console.log('end');
callback();
});
});
req.on('error', function(e) {
console.log('failed');
console.error(e.stack);
callback();
});
req.end();
}
它在我的Mac机器上运行得完美,但我需要这个脚本在使用Windows 7的Windows PC上运行,而这就是它出现错误的地方:
events.js:141
throw er; // Unhandled 'error' event
^
Error: read ECONNRESET
at exports._errnoException (util.js:870:11)
at TCP.onread (net.js:552:26)
req.on('timeout',...)
中仍然遇到错误,所以我按照的代码能够捕获错误,但我仍然不知道如何修复超时和连接关闭问题。 - T.Okahara