Skip to content

Commit 256bc28

Browse files
committed
made some changes related to dns lookup part
1 parent 89037fe commit 256bc28

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

packages/pg/lib/client.js

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -319,21 +319,41 @@ class Client extends EventEmitter {
319319
var client = new Client(currConnectionString)
320320
this.attachErrorListenerOnClientConnection(client)
321321
let lookup = util.promisify(dns.lookup)
322-
await lookup(client.host).then((res) => {
323-
client.host = res.address
324-
client.connectionParameters.host = client.host
322+
let addresses = [client.host]
323+
await lookup(client.host, { family: 0, all: true }).then((res) => {
324+
addresses = res
325325
client.load_balance = false
326326
client.connectionParameters.load_balance = false
327327
client.topology_keys = ''
328328
client.connectionParameters.topology_keys = ''
329+
})
330+
for (let idx = 0; idx < addresses.length; idx++) {
331+
client.host = addresses[idx].address
332+
client.connectionParameters.host = client.host
329333
if (Client.failedHosts.has(client.host)) {
330334
let upHostsList = Client.hostServerInfo.keys()
331335
let upHost = upHostsList.next().value
332336
client.host = upHost
333337
client.connectionParameters.host = client.host
334338
}
335-
})
336-
await client.nowConnect()
339+
await client
340+
.nowConnect()
341+
.then(() => {
342+
idx = addresses.length
343+
})
344+
.catch((err) => {
345+
client.connection =
346+
client.config.connection ||
347+
new Connection({
348+
stream: client.config.stream,
349+
ssl: client.connectionParameters.ssl,
350+
keepAlive: client.config.keepAlive || false,
351+
keepAliveInitialDelayMillis: client.config.keepAliveInitialDelayMillis || 0,
352+
encoding: client.connectionParameters.client_encoding || 'utf8',
353+
})
354+
client._connecting = false
355+
})
356+
}
337357
return client
338358
}
339359

0 commit comments

Comments
 (0)