我已经阅读了很多关于这个主题的内容,但仍然不理解我的代码问题(或者我的逻辑问题/对实际情况的了解)。有人可以解释一下我缺少的东西吗?
基本上,我把这个问题缩小到我连续多次运行以下HTTP GET请求时。如果我只运行循环10次,那很好,但是100次,错误就会被抛出。
这是我的代码:
var request = require('request');
for(var i = 0; i < 100; i++){
request({
url:'http://www.govtrack.us/api/v2/vote',
qs:{
related_bill : 292931
}
}, function(err, res, body){
//console.log(res);
console.log(err);
//console.log(body);
});
}
这是错误:
node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace
at Socket.EventEmitter.addListener (events.js:160:15)
at Socket.Readable.on (_stream_readable.js:689:33)
at Socket.EventEmitter.once (events.js:179:8)
at Request.onResponse (/Users/Josh/Node/Dev/node_modules/request/request.js:625:25)
at ClientRequest.g (events.js:175:14)
at ClientRequest.EventEmitter.emit (events.js:95:17)
at HTTPParser.parserOnIncomingClient [as onIncoming] (http.js:1689:21)
at HTTPParser.parserOnHeadersComplete [as onHeadersComplete] (http.js:120:23)
at Socket.socketOnData [as ondata] (http.js:1584:20)
at TCP.onread (net.js:525:27)