Skip to content

Commit 4fc2787

Browse files
committed
fix: remove unnecessary (un)relaxations
1 parent f46180a commit 4fc2787

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

packages/client/lib/client/enterprise-maintenance-manager.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import RedisSocket from "./socket";
55
import { RedisArgument } from "../..";
66
import { isIP } from "net";
77
import { lookup } from "dns/promises";
8+
import assert from "node:assert";
89

910
export const MAINTENANCE_EVENTS = {
1011
PAUSE_WRITING: "pause-writing",
@@ -33,6 +34,7 @@ export const dbgMaintenance = (...args: any[]) => {
3334
export default class EnterpriseMaintenanceManager extends EventEmitter {
3435
#commandsQueue: RedisCommandsQueue;
3536
#options: RedisClientOptions;
37+
#isMaintenance = 0;
3638

3739
static async getHandshakeCommand(tls: boolean, host: string): Promise<Array<RedisArgument>> {
3840
const movingEndpointType = await determineEndpoint(tls, host);
@@ -104,7 +106,6 @@ export default class EnterpriseMaintenanceManager extends EventEmitter {
104106
host,
105107
port,
106108
});
107-
//todo
108109
newSocket.setMaintenanceTimeout();
109110
dbgMaintenance(`Connecting to new socket: ${host}:${port}`);
110111
await newSocket.connect();
@@ -123,6 +124,12 @@ export default class EnterpriseMaintenanceManager extends EventEmitter {
123124
};
124125

125126
#onMigrating = async () => {
127+
this.#isMaintenance++;
128+
if (this.#isMaintenance > 1) {
129+
dbgMaintenance(`Timeout relaxation already done`);
130+
return;
131+
};
132+
126133
this.#commandsQueue.inMaintenance = true;
127134
this.#commandsQueue.setMaintenanceCommandTimeout(
128135
this.#options.gracefulMaintenance?.relaxedCommandTimeout,
@@ -135,6 +142,13 @@ export default class EnterpriseMaintenanceManager extends EventEmitter {
135142
};
136143

137144
#onMigrated = async () => {
145+
this.#isMaintenance--;
146+
assert(this.#isMaintenance >= 0);
147+
if(this.#isMaintenance > 0) {
148+
dbgMaintenance(`Not ready to unrelax timeouts yet`);
149+
return;
150+
}
151+
138152
this.#commandsQueue.inMaintenance = false;
139153
this.#commandsQueue.setMaintenanceCommandTimeout(undefined);
140154

0 commit comments

Comments
 (0)