Skip to content

Commit 860c5cf

Browse files
committed
--wip-- [skip ci]
1 parent 4851fcf commit 860c5cf

File tree

4 files changed

+23
-30
lines changed

4 files changed

+23
-30
lines changed

packages/client/lib/client/commands-queue.ts

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,23 @@ export default class RedisCommandsQueue {
7171

7272
#pushHandlers: PushHandler[] = [this.#onPush.bind(this)];
7373

74-
#inMaintenance = false;
75-
76-
set inMaintenance(value: boolean) {
77-
this.#inMaintenance = value;
78-
}
79-
8074
#maintenanceCommandTimeout: number | undefined
8175

8276
setMaintenanceCommandTimeout(ms: number | undefined) {
83-
dbgMaintenance(`Setting maintenance command timeout to ${ms}`);
8477
// Prevent possible api misuse
85-
if (this.#maintenanceCommandTimeout === ms) return;
78+
if (this.#maintenanceCommandTimeout === ms) {
79+
dbgMaintenance(`Queue already set maintenanceCommandTimeout to ${ms}, skipping`);
80+
return;
81+
};
8682

83+
dbgMaintenance(`Setting maintenance command timeout to ${ms}`);
8784
this.#maintenanceCommandTimeout = ms;
8885

86+
if(this.#maintenanceCommandTimeout === undefined) {
87+
dbgMaintenance(`Queue will keep maintenanceCommandTimeout for exisitng commands, just to be on the safe side. New commands will receive normal timeouts`);
88+
return;
89+
}
90+
8991
let counter = 0;
9092
const total = this.#toWrite.length;
9193

@@ -96,20 +98,16 @@ export default class RedisCommandsQueue {
9698
// Remove timeout listener if it exists
9799
RedisCommandsQueue.#removeTimeoutListener(command)
98100

99-
// Determine newTimeout
100-
const newTimeout = this.#maintenanceCommandTimeout ?? command.timeout?.originalTimeout;
101-
// if no timeout is given and the command didnt have any timeout before, skip
102-
if (!newTimeout) return;
103-
104101
counter++;
102+
const newTimeout = this.#maintenanceCommandTimeout;
105103

106104
// Overwrite the command's timeout
107105
const signal = AbortSignal.timeout(newTimeout);
108106
command.timeout = {
109107
signal,
110108
listener: () => {
111109
this.#toWrite.remove(node);
112-
command.reject(this.#inMaintenance ? new CommandTimeoutDuringMaintananceError(newTimeout) : new TimeoutError());
110+
command.reject(new CommandTimeoutDuringMaintananceError(newTimeout));
113111
},
114112
originalTimeout: command.timeout?.originalTimeout
115113
};
@@ -224,15 +222,16 @@ export default class RedisCommandsQueue {
224222

225223
// If #maintenanceCommandTimeout was explicitly set, we should
226224
// use it instead of the timeout provided by the command
227-
const timeout = this.#maintenanceCommandTimeout || options?.timeout
225+
const timeout = this.#maintenanceCommandTimeout ?? options?.timeout;
226+
const wasInMaintenance = this.#maintenanceCommandTimeout !== undefined;
228227
if (timeout) {
229228

230229
const signal = AbortSignal.timeout(timeout);
231230
value.timeout = {
232231
signal,
233232
listener: () => {
234233
this.#toWrite.remove(node);
235-
value.reject(this.#inMaintenance ? new CommandTimeoutDuringMaintananceError(timeout) : new TimeoutError());
234+
value.reject(wasInMaintenance ? new CommandTimeoutDuringMaintananceError(timeout) : new TimeoutError());
236235
},
237236
originalTimeout: options?.timeout
238237
};

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export const dbgMaintenance = (...args: any[]) => {
2727
};
2828

2929
export interface MaintenanceUpdate {
30-
inMaintenance: boolean;
3130
relaxedCommandTimeout?: number;
3231
relaxedSocketTimeout?: number;
3332
}
@@ -229,7 +228,6 @@ export default class EnterpriseMaintenanceManager {
229228
}
230229

231230
const update: MaintenanceUpdate = {
232-
inMaintenance: true,
233231
relaxedCommandTimeout: this.#options.maintRelaxedCommandTimeout,
234232
relaxedSocketTimeout: this.#options.maintRelaxedSocketTimeout,
235233
};
@@ -246,7 +244,8 @@ export default class EnterpriseMaintenanceManager {
246244
}
247245

248246
const update: MaintenanceUpdate = {
249-
inMaintenance : false
247+
relaxedCommandTimeout: undefined,
248+
relaxedSocketTimeout: undefined
250249
};
251250

252251
this.#client._maintenanceUpdate(update);

packages/client/lib/client/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -957,9 +957,7 @@ export default class RedisClient<
957957
* @internal
958958
*/
959959
_maintenanceUpdate(update: MaintenanceUpdate) {
960-
this._self.#socket.inMaintenance = update.inMaintenance;
961960
this._self.#socket.setMaintenanceTimeout(update.relaxedSocketTimeout);
962-
this._self.#queue.inMaintenance = update.inMaintenance;
963961
this._self.#queue.setMaintenanceCommandTimeout(update.relaxedCommandTimeout);
964962
}
965963

packages/client/lib/client/socket.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,6 @@ export default class RedisSocket extends EventEmitter {
8585
return this.#socketEpoch;
8686
}
8787

88-
#inMaintenance = false;
89-
90-
set inMaintenance(value: boolean) {
91-
this.#inMaintenance = value;
92-
}
93-
9488
constructor(initiator: RedisSocketInitiator, options?: RedisSocketOptions) {
9589
super();
9690

@@ -249,7 +243,10 @@ export default class RedisSocket extends EventEmitter {
249243

250244
setMaintenanceTimeout(ms?: number) {
251245
dbgMaintenance(`Set socket timeout to ${ms}`);
252-
if (this.#maintenanceTimeout === ms) return;
246+
if (this.#maintenanceTimeout === ms) {
247+
dbgMaintenance(`Socket already set maintenanceCommandTimeout to ${ms}, skipping`);
248+
return;
249+
};
253250

254251
this.#maintenanceTimeout = ms;
255252

@@ -282,8 +279,8 @@ export default class RedisSocket extends EventEmitter {
282279

283280
if (this.#socketTimeout) {
284281
socket.once('timeout', () => {
285-
const error = this.#inMaintenance
286-
? new SocketTimeoutDuringMaintananceError(this.#socketTimeout!)
282+
const error = this.#maintenanceTimeout
283+
? new SocketTimeoutDuringMaintananceError(this.#maintenanceTimeout)
287284
: new SocketTimeoutError(this.#socketTimeout!)
288285
socket.destroy(error);
289286
});

0 commit comments

Comments
 (0)