@@ -100,6 +100,7 @@ class Client extends EventEmitter {
100
100
this . ssl = this . connectionParameters . ssl || false
101
101
this . config = config
102
102
this . prevHostIfUsePublic = this . host
103
+ this . urlHost = this . host
103
104
// As with Password, make SSL->Key (the private key) non-enumerable.
104
105
// It won't show up in stack traces
105
106
// or if the client is console.logged
@@ -253,7 +254,6 @@ class Client extends EventEmitter {
253
254
this . prevHostIfUsePublic = currentHost
254
255
this . host = serverInfo . public_ip
255
256
}
256
-
257
257
if ( this . host && this . host . indexOf ( '/' ) === 0 ) {
258
258
con . connect ( this . host + '/.s.PGSQL.' + this . port )
259
259
} else {
@@ -319,7 +319,7 @@ class Client extends EventEmitter {
319
319
var client = new Client ( currConnectionString )
320
320
this . attachErrorListenerOnClientConnection ( client )
321
321
let lookup = util . promisify ( dns . lookup )
322
- let addresses = [ client . host ]
322
+ let addresses = [ { address : client . host } ]
323
323
await lookup ( client . host , { family : 0 , all : true } ) . then ( ( res ) => {
324
324
addresses = res
325
325
} )
@@ -448,7 +448,23 @@ class Client extends EventEmitter {
448
448
}
449
449
if ( this . checkConnectionMapEmpty ( ) && Client . failedHosts . size === 0 ) {
450
450
lock . release ( )
451
- callback ( error )
451
+ // try with url host and mark that connection type as non-load_balanced
452
+ this . host = this . urlHost
453
+ this . connectionParameters . host = this . host
454
+ this . connectionParameters . load_balance = false
455
+ this . connection =
456
+ this . config . connection ||
457
+ new Connection ( {
458
+ stream : this . config . stream ,
459
+ ssl : this . connectionParameters . ssl ,
460
+ keepAlive : this . config . keepAlive || false ,
461
+ keepAliveInitialDelayMillis : this . config . keepAliveInitialDelayMillis || 0 ,
462
+ encoding : this . connectionParameters . client_encoding || 'utf8' ,
463
+ } )
464
+ this . _connecting = false
465
+ Client . hostServerInfo . clear ( )
466
+ Client . connectionMap . clear ( )
467
+ this . connect ( callback )
452
468
return
453
469
}
454
470
lock . release ( )
@@ -485,7 +501,22 @@ class Client extends EventEmitter {
485
501
}
486
502
if ( this . checkConnectionMapEmpty ( ) && Client . failedHosts . size === 0 ) {
487
503
lock . release ( )
488
- reject ( error )
504
+ this . host = this . urlHost
505
+ this . connectionParameters . host = this . host
506
+ this . connectionParameters . load_balance = false
507
+ this . connection =
508
+ this . config . connection ||
509
+ new Connection ( {
510
+ stream : this . config . stream ,
511
+ ssl : this . connectionParameters . ssl ,
512
+ keepAlive : this . config . keepAlive || false ,
513
+ keepAliveInitialDelayMillis : this . config . keepAliveInitialDelayMillis || 0 ,
514
+ encoding : this . connectionParameters . client_encoding || 'utf8' ,
515
+ } )
516
+ this . _connecting = false
517
+ Client . hostServerInfo . clear ( )
518
+ Client . connectionMap . clear ( )
519
+ this . connect ( callback )
489
520
return
490
521
}
491
522
lock . release ( )
0 commit comments