This commit is contained in:
Martin Cizek 2020-09-17 17:49:58 +02:00
parent f0c864ca85
commit d32a765ee9
1 changed files with 13 additions and 11 deletions

View File

@ -795,13 +795,7 @@ Client.prototype.connect = function connect () {
// Establish basic socket connection
function connectSocket (cb) {
self._nextServer = (self._nextServer + 1) % self.urls.length
self.url = self.urls[self._nextServer]
if (self.url) {
self.host = self.url.hostname
self.port = self.url.port
self.secure = self.url.secure
}
var server = self.urls[self._nextServer]
cb = once(cb)
@ -831,16 +825,17 @@ Client.prototype.connect = function connect () {
setupClient(cb)
}
var port = (self.port || self.socketPath)
var port = (server && server.port) || self.socketPath
var host = server && server.hostname
if (self.secure) {
socket = tls.connect(port, self.host, self.tlsOptions)
socket = tls.connect(port, host, self.tlsOptions)
socket.once('secureConnect', onConnect)
} else {
socket = net.connect(port, self.host)
socket = net.connect(port, host)
socket.once('connect', onConnect)
}
socket.once('error', onResult)
initSocket(self.url)
initSocket(server)
// Setup connection timeout handling, if desired
if (self.connectTimeout) {
@ -976,6 +971,13 @@ Client.prototype.connect = function connect () {
self.emit('socketTimeout')
socket.end()
})
var server = self.urls[self._nextServer]
if (server) {
self.host = server.hostname
self.port = server.port
self.secure = server.secure
}
}
var retry