Skip to content

Commit d94f97d

Browse files
ShogunPandaAVVS
authored andcommitted
fix: Make sure script caches interval is cleared. [#1215]
1 parent 5497b09 commit d94f97d

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-0
lines changed

lib/cluster/index.ts

+4
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ class Cluster extends EventEmitter {
331331
this.setStatus("disconnecting");
332332

333333
clearInterval(this._addedScriptHashesCleanInterval);
334+
this._addedScriptHashesCleanInterval = null;
334335

335336
if (!reconnect) {
336337
this.manuallyClosing = true;
@@ -362,6 +363,9 @@ class Cluster extends EventEmitter {
362363
const status = this.status;
363364
this.setStatus("disconnecting");
364365

366+
clearInterval(this._addedScriptHashesCleanInterval);
367+
this._addedScriptHashesCleanInterval = null;
368+
365369
this.manuallyClosing = true;
366370

367371
if (this.reconnectTimeout) {

lib/redis/index.ts

+6
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ Redis.prototype.connect = function (callback) {
406406
*/
407407
Redis.prototype.disconnect = function (reconnect) {
408408
clearInterval(this._addedScriptHashesCleanInterval);
409+
this._addedScriptHashesCleanInterval = null;
409410

410411
if (!reconnect) {
411412
this.manuallyClosing = true;
@@ -698,6 +699,11 @@ Redis.prototype.sendCommand = function (command, stream) {
698699
return command.promise;
699700
}
700701

702+
if (command.name === "quit") {
703+
clearInterval(this._addedScriptHashesCleanInterval);
704+
this._addedScriptHashesCleanInterval = null;
705+
}
706+
701707
let writable =
702708
this.status === "ready" ||
703709
(!stream &&

test/functional/cluster/connect.ts

+28
Original file line numberDiff line numberDiff line change
@@ -411,3 +411,31 @@ describe("cluster:connect", function () {
411411
});
412412
});
413413
});
414+
415+
describe("cluster:disconnect", function () {
416+
it("should clear the added script hashes interval when disconnecting", function (done) {
417+
new MockServer(30001);
418+
const cluster = new Cluster([{ host: "127.0.0.1", port: "30001" }], {
419+
enableReadyCheck: false,
420+
});
421+
cluster.once("ready", function () {
422+
cluster.disconnect();
423+
424+
expect(cluster._addedScriptHashesCleanInterval).to.be.null;
425+
done();
426+
});
427+
});
428+
429+
it("should clear the added script hashes interval when quitting", function (done) {
430+
new MockServer(30001);
431+
const cluster = new Cluster([{ host: "127.0.0.1", port: "30001" }], {
432+
enableReadyCheck: false,
433+
});
434+
cluster.once("ready", function () {
435+
cluster.quit();
436+
437+
expect(cluster._addedScriptHashesCleanInterval).to.be.null;
438+
done();
439+
});
440+
});
441+
});

test/functional/connection.ts

+22
Original file line numberDiff line numberDiff line change
@@ -475,3 +475,25 @@ describe("connection", function () {
475475
});
476476
});
477477
});
478+
479+
describe("disconnection", function () {
480+
it("should clear the added script hashes interval when disconnecting", function (done) {
481+
const redis = new Redis();
482+
redis.once("ready", function () {
483+
redis.disconnect();
484+
485+
expect(redis._addedScriptHashesCleanInterval).to.be.null;
486+
done();
487+
});
488+
});
489+
490+
it("should clear the added script hashes interval when quitting", function (done) {
491+
const redis = new Redis();
492+
redis.once("ready", function () {
493+
redis.quit();
494+
495+
expect(redis._addedScriptHashesCleanInterval).to.be.null;
496+
done();
497+
});
498+
});
499+
});

0 commit comments

Comments
 (0)