0

我已经阅读了很多关于这个主题的内容,但仍然不理解我的代码的问题(或者我的逻辑问题/对实际情况的理解)。有人可以解释我错过了什么吗?

基本上,我已经将这个问题缩小到当我连续多次运行以下 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)
4

1 回答 1

0

它看起来像一个错误request,这里有一个讨论:https ://github.com/mikeal/request/pull/623

于 2013-10-26T18:30:03.077 回答