AMQP警告:检测到可能的EventEmitter内存泄漏。 11名听众补充道。

时间:2013-09-13 16:07:38

标签: node.js rabbitmq amqp node-amqp

我收到Node.js中的以下错误,我认为它与AMQP有关。

(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace
    at Connection.EventEmitter.addListener (events.js:160:15)
    at Connection.EventEmitter.once (events.js:179:8)
    at Connection.connect (/var/www/project/app/node_modules/amqp/amqp.js:1084:8)
    at Connection.reconnect (/var/www/project/app/node_modules/amqp/amqp.js:1049:8)
    at null._onTimeout (/var/www/project/app/node_modules/amqp/amqp.js:886:16)
    at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)

有人能指出问题所在吗?

继承我用于连接的模块中的代码:

JackRabbit.prototype.subscribe = function subscribe(recievedCB, routingKey) {
    var self = this;
    var route = routingKey || '#';

    self.createConnection(function(rabbitMq, ex, q) {
        // Catch all messages
        q.bind(self.config.exchangeName, route);

        // Receive messages
        q.subscribe(self.config.messageOptions, function(msg, headers, deliveryInfo) {            
            recievedCB(q, msg, headers, deliveryInfo);

            // Clsoe connection
            //rabbitMq.end();
        });        
    });
}

这就是我称之为方法的地方:

var scrapRequestRecieved = function(q, msg, headers, deliveryInfo) {
    console.log("SC msg: %j", msg);

    /** Callback function shifts the completed job from the queue. */
    phantom.scrapeUrls(msg.urls, function() {
        console.log("SC DONE");
        q.shift();
    });
};
rabbit.subscribe(scrapRequestRecieved, "sc.#");

2 个答案:

答案 0 :(得分:2)

经过一些搜索后,问题似乎是由AMPQ的旧连接逻辑引起的。每次尝试重新连接时,都会添加一个新的侦听器,而不会删除旧的侦听器。此问题已在this拉取请求中得到修复。

答案 1 :(得分:1)

最后一个版本0.1.8包含@hexacyanide评论的拉取请求。