Skip to content

Commit

Permalink
fix: Make sure script caches interval is cleared. [#1215]
Browse files Browse the repository at this point in the history
  • Loading branch information
ShogunPanda authored and AVVS committed Oct 28, 2020
1 parent 5497b09 commit d94f97d
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/cluster/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ class Cluster extends EventEmitter {
this.setStatus("disconnecting");

clearInterval(this._addedScriptHashesCleanInterval);
this._addedScriptHashesCleanInterval = null;

if (!reconnect) {
this.manuallyClosing = true;
Expand Down Expand Up @@ -362,6 +363,9 @@ class Cluster extends EventEmitter {
const status = this.status;
this.setStatus("disconnecting");

clearInterval(this._addedScriptHashesCleanInterval);
this._addedScriptHashesCleanInterval = null;

this.manuallyClosing = true;

if (this.reconnectTimeout) {
Expand Down
6 changes: 6 additions & 0 deletions lib/redis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ Redis.prototype.connect = function (callback) {
*/
Redis.prototype.disconnect = function (reconnect) {
clearInterval(this._addedScriptHashesCleanInterval);
this._addedScriptHashesCleanInterval = null;

if (!reconnect) {
this.manuallyClosing = true;
Expand Down Expand Up @@ -698,6 +699,11 @@ Redis.prototype.sendCommand = function (command, stream) {
return command.promise;
}

if (command.name === "quit") {
clearInterval(this._addedScriptHashesCleanInterval);
this._addedScriptHashesCleanInterval = null;
}

let writable =
this.status === "ready" ||
(!stream &&
Expand Down
28 changes: 28 additions & 0 deletions test/functional/cluster/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,3 +411,31 @@ describe("cluster:connect", function () {
});
});
});

describe("cluster:disconnect", function () {
it("should clear the added script hashes interval when disconnecting", function (done) {
new MockServer(30001);
const cluster = new Cluster([{ host: "127.0.0.1", port: "30001" }], {
enableReadyCheck: false,
});
cluster.once("ready", function () {
cluster.disconnect();

expect(cluster._addedScriptHashesCleanInterval).to.be.null;
done();
});
});

it("should clear the added script hashes interval when quitting", function (done) {
new MockServer(30001);
const cluster = new Cluster([{ host: "127.0.0.1", port: "30001" }], {
enableReadyCheck: false,
});
cluster.once("ready", function () {
cluster.quit();

expect(cluster._addedScriptHashesCleanInterval).to.be.null;
done();
});
});
});
22 changes: 22 additions & 0 deletions test/functional/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,3 +475,25 @@ describe("connection", function () {
});
});
});

describe("disconnection", function () {
it("should clear the added script hashes interval when disconnecting", function (done) {
const redis = new Redis();
redis.once("ready", function () {
redis.disconnect();

expect(redis._addedScriptHashesCleanInterval).to.be.null;
done();
});
});

it("should clear the added script hashes interval when quitting", function (done) {
const redis = new Redis();
redis.once("ready", function () {
redis.quit();

expect(redis._addedScriptHashesCleanInterval).to.be.null;
done();
});
});
});

0 comments on commit d94f97d

Please sign in to comment.