diff --git a/lib/cartodb/varnish.js b/lib/cartodb/varnish.js index 3360a0a9..977f5bdc 100644 --- a/lib/cartodb/varnish.js +++ b/lib/cartodb/varnish.js @@ -8,6 +8,7 @@ var net = require('net') function VarnishClient(host, port, ready_callback) { + var self = this; var ready = false; var cmd_callback = null; var client = null; @@ -39,6 +40,14 @@ function VarnishClient(host, port, ready_callback) { }); + client.on('error', function(err) { + console.log("[ERROR] some problem in varnish connection"); + }); + + client.on('close', function() { + self.close(); + }); + // sends the command to the server function _send(cmd, callback) { cmd_callback = callback; @@ -98,6 +107,7 @@ function VarnishPool(opts, ready) { function VarnishQueue(host, port) { + var MAX_QUEUE = 2000; var queue = []; var ready = false; @@ -122,6 +132,10 @@ function VarnishQueue(host, port) { this.run_cmd = function(cmd) { queue.push(cmd); + if(queue.length > MAX_QUEUE) { + console.log("varnish commando queu too long, removing commands"); + queue.pop(); + } if(ready) { _send_pending(); }