@@ -6,7 +6,7 @@ import { RedisArgument } from "../..";
66import { isIP } from "net" ;
77import { lookup } from "dns/promises" ;
88import assert from "node:assert" ;
9- import { setTimeout } from ' node:timers/promises'
9+ import { setTimeout } from " node:timers/promises" ;
1010
1111export const MAINTENANCE_EVENTS = {
1212 PAUSE_WRITING : "pause-writing" ,
@@ -90,13 +90,13 @@ export default class EnterpriseMaintenanceManager extends EventEmitter {
9090 }
9191
9292 #onPush = ( push : Array < any > ) : boolean => {
93- dbgMaintenance ( push ) ;
93+ dbgMaintenance ( "ONPUSH:" , push . map ( String ) ) ;
9494 switch ( push [ 0 ] . toString ( ) ) {
9595 case PN . MOVING : {
9696 // [ 'MOVING', '17', '15', '54.78.247.156:12075' ]
9797 // ^seq ^after ^new ip
9898 const afterSeconds = push [ 2 ] ;
99- const url : string | null = push [ 3 ] ;
99+ const url : string | null = push [ 3 ] ? String ( push [ 3 ] ) : null ;
100100 dbgMaintenance ( "Received MOVING:" , afterSeconds , url ) ;
101101 this . #onMoving( afterSeconds , url ) ;
102102 return true ;
@@ -131,32 +131,32 @@ export default class EnterpriseMaintenanceManager extends EventEmitter {
131131 // 6. [ACTION] Resume writing -> we are going to write to the new socket from now on
132132 #onMoving = async (
133133 afterSeconds : number ,
134- url : string | null
134+ url : string | null ,
135135 ) : Promise < void > => {
136136 // 1 [EVENT] MOVING PN received
137137 this . #onMigrating( ) ;
138138
139- let host : string
140- let port : number
139+ let host : string ;
140+ let port : number ;
141141
142142 // The special value `none` indicates that the `MOVING` message doesn’t need
143143 // to contain an endpoint. Instead it contains the value `null` then. In
144144 // such a corner case, the client is expected to schedule a graceful
145145 // reconnect to its currently configured endpoint after half of the grace
146146 // 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 ;
156156 dbgMaintenance ( `Wait for ${ waitTime } ms` ) ;
157157 await setTimeout ( waitTime ) ;
158158 } else {
159- const split = url . split ( ':' ) ;
159+ const split = url . split ( ":" ) ;
160160 host = split [ 0 ] ;
161161 port = Number ( split [ 1 ] ) ;
162162 }
@@ -262,7 +262,9 @@ async function determineEndpoint(
262262) : Promise < MovingEndpointType > {
263263 assert ( options . maintMovingEndpointType !== undefined ) ;
264264 if ( options . maintMovingEndpointType !== "auto" ) {
265- dbgMaintenance ( `Determine endpoint type: ${ options . maintMovingEndpointType } ` ) ;
265+ dbgMaintenance (
266+ `Determine endpoint type: ${ options . maintMovingEndpointType } ` ,
267+ ) ;
266268 return options . maintMovingEndpointType ;
267269 }
268270
0 commit comments