@@ -98,19 +98,24 @@ ServerSchema.method('getServerConnectInfo', async function (): Promise<IServerCo
9898 // * and just Hope For The Best:tm:
9999 let target = randomIP ;
100100
101- // * Check the random IP and start the race at the same time, preferring
102- // * the result of the random IP should it succeed. Worst case scenario
103- // * this takes 2 seconds to complete
104- const [ randomResult , raceResult ] = await Promise . allSettled ( [
105- healthCheck ( { host : randomIP , port : this . health_check_port ! } ) ,
106- Promise . race ( healthCheckTargets . map ( target => healthCheck ( target ) ) )
107- ] ) ;
108-
109- if ( randomResult . status === 'rejected' ) {
110- if ( raceResult . status === 'fulfilled' ) {
111- target = raceResult . value ;
112- } else {
113- LOG_WARN ( `Server ${ this . service_name } failed to find healthy NEX server. Using the randomly selected IP ${ target } ` ) ;
101+ // * If the server only has 1 IP, healthCheckTargets will be empty and Promise.race
102+ // * will never resolve. In those cases, just skip this step entirely since we'd
103+ // * have to use that singular IP regardless
104+ if ( healthCheckTargets . length !== 0 ) {
105+ // * Check the random IP and start the race at the same time, preferring
106+ // * the result of the random IP should it succeed. Worst case scenario
107+ // * this takes 2 seconds to complete
108+ const [ randomResult , raceResult ] = await Promise . allSettled ( [
109+ healthCheck ( { host : randomIP , port : this . health_check_port ! } ) ,
110+ Promise . race ( healthCheckTargets . map ( target => healthCheck ( target ) ) )
111+ ] ) ;
112+
113+ if ( randomResult . status === 'rejected' ) {
114+ if ( raceResult . status === 'fulfilled' ) {
115+ target = raceResult . value ;
116+ } else {
117+ LOG_WARN ( `Server ${ this . service_name } failed to find healthy NEX server. Using the randomly selected IP ${ target } ` ) ;
118+ }
114119 }
115120 }
116121
0 commit comments