Node.js:某个时间的并行GET请求出现未处理的错误
Node.js : Unhandled error on parallel GET requests on a certain time
我正在使用请求/请求模块向API发送大约100个并行GET
请求。我遇到的问题是关于80th to 100th request
的随机问题,node
抛出了这个异常:
events.js:141
throw er; // Unhandled 'error' event
^
Error: connect ETIMEDOUT 0.0.0.0:80 //a dummy ip
at Object.exports._errnoException (util.js:860:11)
at exports._exceptionWithHostPort (util.js:883:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1063:14)
以下是我的请求默认值:
var apiRequest = request.defaults({
url : url, //response is in xml format
headers : {
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Accept-Language': 'en-US,en;q=0.8'
},
method : 'GET',
gzip : true,
encoding : 'utf8',
pool: {maxSockets: Infinity},
forever : true,
timeout : 120000
});
此外,我请求在数组上使用循环
通过递归地请求失败的URL on error event
直到没有超时为止,修复了我的问题:
function getAPI(url) {
var apiRequest = request.defaults({
url : url,
headers : {
'Accept': 'text/html,application/xhtml+xml,application/xml'
},
method : 'GET',
gzip : true
});
apiRequest(function (error, response, body) {
}).on('error', function(e){
getAPI(this.uri.href);//this is important
}).end();
}
相关文章:
- 未处理的拒绝MongoError:无法连接到MongoDB中的服务器
- 错误“;未处理'错误'事件“;在运行yo发电机之后
- jQuery on('单击',..)未处理附加的元素
- NodeJS未处理的拒绝错误:Can't在发送标头后设置标头
- 可以clearTimeout删除JavaScript中已触发超时事件的未处理回调
- Ajax/JSON请求php处理页面
- 未处理的 JavaScript 异常终止 MSAppHost/WWAHost.exe
- Angular2 发布请求未向服务器发送正确的数据
- 未处理角度指令
- Vue.js路由未处理任何方法
- 最近未处理动态添加的内容
- 节点JSON https请求未定义
- 此 Ajax 请求未响应相应的 JSON 文件
- 信息-未处理的socket.io url
- Trigger.io::未处理的意向结果
- Ajax请求未响应
- 可能未处理通过测试时出现错误
- 请求管道处理错误
- 中止Angular中挂起的http请求未中止
- Node.js:某个时间的并行GET请求出现未处理的错误