Skip to content

Commit c7188bc

Browse files
committed
address PR comments
1 parent 7a4cd50 commit c7188bc

File tree

5 files changed

+21
-23
lines changed

5 files changed

+21
-23
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import encodeCommand from '../RESP/encoder';
33
import { Decoder, PUSH_TYPE_MAPPING, RESP_TYPES } from '../RESP/decoder';
44
import { TypeMapping, ReplyUnion, RespVersions, RedisArgument } from '../RESP/types';
55
import { ChannelListeners, PubSub, PubSubCommand, PubSubListener, PubSubType, PubSubTypeListeners } from './pub-sub';
6-
import { AbortError, ErrorReply, CommandTimeoutDuringMaintananceError, TimeoutError } from '../errors';
6+
import { AbortError, ErrorReply, CommandTimeoutDuringMaintenanceError, TimeoutError } from '../errors';
77
import { MonitorCallback } from '.';
88
import { dbgMaintenance } from './enterprise-maintenance-manager';
99

@@ -107,7 +107,7 @@ export default class RedisCommandsQueue {
107107
signal,
108108
listener: () => {
109109
this.#toWrite.remove(node);
110-
command.reject(new CommandTimeoutDuringMaintananceError(newTimeout));
110+
command.reject(new CommandTimeoutDuringMaintenanceError(newTimeout));
111111
},
112112
originalTimeout: command.timeout?.originalTimeout
113113
};
@@ -231,7 +231,7 @@ export default class RedisCommandsQueue {
231231
signal,
232232
listener: () => {
233233
this.#toWrite.remove(node);
234-
value.reject(wasInMaintenance ? new CommandTimeoutDuringMaintananceError(timeout) : new TimeoutError());
234+
value.reject(wasInMaintenance ? new CommandTimeoutDuringMaintenanceError(timeout) : new TimeoutError());
235235
},
236236
originalTimeout: options?.timeout
237237
};

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

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -221,27 +221,25 @@ export default class EnterpriseMaintenanceManager {
221221
} else {
222222
tmpOptions.socket = {
223223
...tmpOptions.socket,
224-
host, port
224+
host,
225+
port
225226
}
226227
}
227228
const tmpClient = this.#client.duplicate(tmpOptions);
228229
dbgMaintenance(`Tmp client created in ${( performance.now() - start ).toFixed(2)}ms`);
229-
dbgMaintenance(`Connecting tmp client: ${host}:${port}`);
230-
start = performance.now();
230+
dbgMaintenance(
231+
`Set timeout for tmp client to ${this.#options.maintRelaxedSocketTimeout}`,
232+
);
231233
tmpClient._maintenanceUpdate({
232234
relaxedCommandTimeout: this.#options.maintRelaxedCommandTimeout,
233235
relaxedSocketTimeout: this.#options.maintRelaxedSocketTimeout,
234236
});
237+
dbgMaintenance(`Connecting tmp client: ${host}:${port}`);
238+
start = performance.now();
235239
await tmpClient.connect();
236240
dbgMaintenance(`Connected to tmp client in ${(performance.now() - start).toFixed(2)}ms`);
237241
// 3 [EVENT] New socket connected
238242

239-
//TODO
240-
// dbgMaintenance(
241-
// `Set timeout for new socket to ${this.#options.maintRelaxedSocketTimeout}`,
242-
// );
243-
// newSocket.setMaintenanceTimeout(this.#options.maintRelaxedSocketTimeout);
244-
245243
dbgMaintenance(`Wait for all in-flight commands to complete`);
246244
await this.#commandsQueue.waitForInflightCommandsToComplete();
247245
dbgMaintenance(`In-flight commands completed`);
@@ -260,7 +258,7 @@ export default class EnterpriseMaintenanceManager {
260258
this.#onMigrated();
261259
};
262260

263-
#onMigrating = async () => {
261+
#onMigrating = () => {
264262
this.#isMaintenance++;
265263
if (this.#isMaintenance > 1) {
266264
dbgMaintenance(`Timeout relaxation already done`);
@@ -275,9 +273,9 @@ export default class EnterpriseMaintenanceManager {
275273
this.#client._maintenanceUpdate(update);
276274
};
277275

278-
#onMigrated = async () => {
279-
this.#isMaintenance--;
280-
assert(this.#isMaintenance >= 0);
276+
#onMigrated = () => {
277+
//ensure that #isMaintenance doesnt go under 0
278+
this.#isMaintenance = Math.max(this.#isMaintenance - 1, 0);
281279
if (this.#isMaintenance > 0) {
282280
dbgMaintenance(`Not ready to unrelax timeouts yet`);
283281
return;

packages/client/lib/client/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,15 @@ export interface RedisClientOptions<
171171
/**
172172
* Specifies a more relaxed timeout (in milliseconds) for commands during a maintenance window.
173173
* This helps minimize command timeouts during maintenance. If not provided, the `commandOptions.timeout`
174-
* will be used instead. Timeouts during maintenance period result in a `CommandTimeoutDuringMaintanance` error.
174+
* will be used instead. Timeouts during maintenance period result in a `CommandTimeoutDuringMaintenance` error.
175175
*
176176
* The default is 10000
177177
*/
178178
maintRelaxedCommandTimeout?: number;
179179
/**
180180
* Specifies a more relaxed timeout (in milliseconds) for the socket during a maintenance window.
181181
* This helps minimize socket timeouts during maintenance. If not provided, the `socket.timeout`
182-
* will be used instead. Timeouts during maintenance period result in a `SocketTimeoutDuringMaintanance` error.
182+
* will be used instead. Timeouts during maintenance period result in a `SocketTimeoutDuringMaintenance` error.
183183
*
184184
* The default is 10000
185185
*/
@@ -943,7 +943,7 @@ export default class RedisClient<
943943
}
944944

945945
/**
946-
* @intenal
946+
* @internal
947947
*/
948948
_insertSocket(socket: RedisSocket) {
949949
if(this._self.#socket) {

packages/client/lib/client/socket.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { EventEmitter, once } from 'node:events';
22
import net from 'node:net';
33
import tls from 'node:tls';
4-
import { ConnectionTimeoutError, ClientClosedError, SocketClosedUnexpectedlyError, ReconnectStrategyError, SocketTimeoutError, SocketTimeoutDuringMaintananceError } from '../errors';
4+
import { ConnectionTimeoutError, ClientClosedError, SocketClosedUnexpectedlyError, ReconnectStrategyError, SocketTimeoutError, SocketTimeoutDuringMaintenanceError } from '../errors';
55
import { setTimeout } from 'node:timers/promises';
66
import { RedisArgument } from '../RESP/types';
77
import { dbgMaintenance } from './enterprise-maintenance-manager';
@@ -280,7 +280,7 @@ export default class RedisSocket extends EventEmitter {
280280
if (this.#socketTimeout) {
281281
socket.once('timeout', () => {
282282
const error = this.#maintenanceTimeout
283-
? new SocketTimeoutDuringMaintananceError(this.#maintenanceTimeout)
283+
? new SocketTimeoutDuringMaintenanceError(this.#maintenanceTimeout)
284284
: new SocketTimeoutError(this.#socketTimeout!)
285285
socket.destroy(error);
286286
});

packages/client/lib/errors.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ export class BlobError extends ErrorReply {}
7171

7272
export class TimeoutError extends Error {}
7373

74-
export class SocketTimeoutDuringMaintananceError extends TimeoutError {
74+
export class SocketTimeoutDuringMaintenanceError extends TimeoutError {
7575
constructor(timeout: number) {
7676
super(`Socket timeout during maintenance. Expecting data, but didn't receive any in ${timeout}ms.`);
7777
}
7878
}
7979

80-
export class CommandTimeoutDuringMaintananceError extends TimeoutError {
80+
export class CommandTimeoutDuringMaintenanceError extends TimeoutError {
8181
constructor(timeout: number) {
8282
super(`Command timeout during maintenance. Waited to write command for more than ${timeout}ms.`);
8383
}

0 commit comments

Comments
 (0)