@@ -6,7 +6,7 @@ import { RedisArgument } from "../..";
6
6
import { isIP } from "net" ;
7
7
import { lookup } from "dns/promises" ;
8
8
import assert from "node:assert" ;
9
- import { setTimeout } from ' node:timers/promises'
9
+ import { setTimeout } from " node:timers/promises" ;
10
10
11
11
export const MAINTENANCE_EVENTS = {
12
12
PAUSE_WRITING : "pause-writing" ,
@@ -90,13 +90,13 @@ export default class EnterpriseMaintenanceManager extends EventEmitter {
90
90
}
91
91
92
92
#onPush = ( push : Array < any > ) : boolean => {
93
- dbgMaintenance ( push ) ;
93
+ dbgMaintenance ( "ONPUSH:" , push . map ( String ) ) ;
94
94
switch ( push [ 0 ] . toString ( ) ) {
95
95
case PN . MOVING : {
96
96
// [ 'MOVING', '17', '15', '54.78.247.156:12075' ]
97
97
// ^seq ^after ^new ip
98
98
const afterSeconds = push [ 2 ] ;
99
- const url : string | null = push [ 3 ] ;
99
+ const url : string | null = push [ 3 ] ? String ( push [ 3 ] ) : null ;
100
100
dbgMaintenance ( "Received MOVING:" , afterSeconds , url ) ;
101
101
this . #onMoving( afterSeconds , url ) ;
102
102
return true ;
@@ -131,32 +131,32 @@ export default class EnterpriseMaintenanceManager extends EventEmitter {
131
131
// 6. [ACTION] Resume writing -> we are going to write to the new socket from now on
132
132
#onMoving = async (
133
133
afterSeconds : number ,
134
- url : string | null
134
+ url : string | null ,
135
135
) : Promise < void > => {
136
136
// 1 [EVENT] MOVING PN received
137
137
this . #onMigrating( ) ;
138
138
139
- let host : string
140
- let port : number
139
+ let host : string ;
140
+ let port : number ;
141
141
142
142
// The special value `none` indicates that the `MOVING` message doesn’t need
143
143
// to contain an endpoint. Instead it contains the value `null` then. In
144
144
// such a corner case, the client is expected to schedule a graceful
145
145
// reconnect to its currently configured endpoint after half of the grace
146
146
// period that was communicated by the server is over.
147
- if ( url === null ) {
148
- assert ( this . #options. maintMovingEndpointType === ' none' ) ;
149
- assert ( this . #options. socket !== undefined )
150
- assert ( ' host' in this . #options. socket )
151
- assert ( typeof this . #options. socket . host === ' string' )
152
- host = this . #options. socket . host
153
- assert ( typeof this . #options. socket . port === ' number' )
154
- port = this . #options. socket . port
155
- const waitTime = afterSeconds * 1000 / 2 ;
147
+ if ( url === null ) {
148
+ assert ( this . #options. maintMovingEndpointType === " none" ) ;
149
+ assert ( this . #options. socket !== undefined ) ;
150
+ assert ( " host" in this . #options. socket ) ;
151
+ assert ( typeof this . #options. socket . host === " string" ) ;
152
+ host = this . #options. socket . host ;
153
+ assert ( typeof this . #options. socket . port === " number" ) ;
154
+ port = this . #options. socket . port ;
155
+ const waitTime = ( afterSeconds * 1000 ) / 2 ;
156
156
dbgMaintenance ( `Wait for ${ waitTime } ms` ) ;
157
157
await setTimeout ( waitTime ) ;
158
158
} else {
159
- const split = url . split ( ':' ) ;
159
+ const split = url . split ( ":" ) ;
160
160
host = split [ 0 ] ;
161
161
port = Number ( split [ 1 ] ) ;
162
162
}
@@ -262,7 +262,9 @@ async function determineEndpoint(
262
262
) : Promise < MovingEndpointType > {
263
263
assert ( options . maintMovingEndpointType !== undefined ) ;
264
264
if ( options . maintMovingEndpointType !== "auto" ) {
265
- dbgMaintenance ( `Determine endpoint type: ${ options . maintMovingEndpointType } ` ) ;
265
+ dbgMaintenance (
266
+ `Determine endpoint type: ${ options . maintMovingEndpointType } ` ,
267
+ ) ;
266
268
return options . maintMovingEndpointType ;
267
269
}
268
270
0 commit comments