Skip to content

Commit a6357d6

Browse files
committed
Merge pull request #854 from fintura/memory-leak
Fix memory leak. See #723 and thx to @rahar
2 parents c846ed7 + 46e2dc2 commit a6357d6

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

index.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,25 @@ RedisClient.prototype.send_offline_queue = function () {
394394
}
395395
};
396396

397-
RedisClient.prototype.connection_gone = function (why) {
398-
var self = this;
397+
var retry_connection = function (self) {
398+
debug("Retrying connection...");
399+
400+
self.emit("reconnecting", {
401+
delay: self.retry_delay,
402+
attempt: self.attempts
403+
});
404+
405+
self.retry_totaltime += self.retry_delay;
406+
self.attempts += 1;
407+
self.retry_delay = Math.round(self.retry_delay * self.retry_backoff);
408+
409+
self.stream = net.createConnection(self.connectionOption);
410+
self.install_stream_listeners();
411+
412+
self.retry_timer = null;
413+
};
399414

415+
RedisClient.prototype.connection_gone = function (why) {
400416
// If a retry is already in progress, just let that happen
401417
if (this.retry_timer) {
402418
return;
@@ -452,23 +468,7 @@ RedisClient.prototype.connection_gone = function (why) {
452468

453469
debug("Retry connection in " + this.retry_delay + " ms");
454470

455-
this.retry_timer = setTimeout(function () {
456-
debug("Retrying connection...");
457-
458-
self.emit("reconnecting", {
459-
delay: self.retry_delay,
460-
attempt: self.attempts
461-
});
462-
463-
self.retry_totaltime += self.retry_delay;
464-
self.attempts += 1;
465-
self.retry_delay = Math.round(self.retry_delay * self.retry_backoff);
466-
467-
self.stream = net.createConnection(self.connectionOption);
468-
self.install_stream_listeners();
469-
470-
self.retry_timer = null;
471-
}, this.retry_delay);
471+
this.retry_timer = setTimeout(retry_connection, this.retry_delay, this);
472472
};
473473

474474
RedisClient.prototype.on_data = function (data) {

test/commands/multi.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,11 @@ describe("The 'multi' method", function () {
250250
});
251251

252252
it('reports EXECABORT exceptions when they occur (while queueing)', function (done) {
253-
client.multi().config("bar").set("foo").exec(function (err, reply) {
253+
client.multi().config("bar").set("foo").set("bar").exec(function (err, reply) {
254254
assert.equal(err.code, "EXECABORT");
255255
assert.equal(reply, undefined, "The reply should have been discarded");
256256
assert(err.message.match(/^EXECABORT/), "Error message should begin with EXECABORT");
257-
assert.equal(err.errors.length, 1, "err.errors should have 1 items");
257+
assert.equal(err.errors.length, 2, "err.errors should have 2 items");
258258
assert.strictEqual(err.errors[0].command_used, 'SET');
259259
assert.strictEqual(err.errors[0].position, 1);
260260
assert(/^ERR/.test(err.errors[0].message), "Actuall error message should begin with ERR");

0 commit comments

Comments
 (0)