@@ -203,7 +203,6 @@ def __init__(self, host, port, afi, **configs):
203
203
self .afi = afi
204
204
self ._init_host = host
205
205
self ._init_port = port
206
- self ._init_afi = afi
207
206
self .in_flight_requests = collections .deque ()
208
207
self ._api_versions = None
209
208
@@ -264,7 +263,7 @@ def connect(self):
264
263
log .debug ('%s: creating new socket' , self )
265
264
# if self.afi is set to AF_UNSPEC, then we need to do a name
266
265
# resolution and try all available address families
267
- if self ._init_afi == socket .AF_UNSPEC :
266
+ if self .afi == socket .AF_UNSPEC :
268
267
if self ._gai is None :
269
268
# XXX: all DNS functions in Python are blocking. If we really
270
269
# want to be non-blocking here, we need to use a 3rd-party
@@ -291,10 +290,10 @@ def connect(self):
291
290
self ._gai_index += 1
292
291
while True :
293
292
if self ._gai_index >= len (self ._gai ):
294
- error = 'Unable to connect to any of the names for {0}:{1}' . format (
295
- self ._init_host , self ._init_port )
296
- log . error ( error )
297
- self .close ( Errors . ConnectionError ( error ))
293
+ log . error ( 'Unable to connect to any of the names for {0}:{1}'
294
+ . format ( self ._init_host , self ._init_port ) )
295
+ self . _gai = None
296
+ self ._gai_index = 0
298
297
return
299
298
afi , _ , __ , ___ , sockaddr = self ._gai [self ._gai_index ]
300
299
if afi not in (socket .AF_INET , socket .AF_INET6 ):
@@ -304,7 +303,7 @@ def connect(self):
304
303
self .host , self .port = sockaddr [:2 ]
305
304
self ._sock = socket .socket (afi , socket .SOCK_STREAM )
306
305
else :
307
- self ._sock = socket .socket (self ._init_afi , socket .SOCK_STREAM )
306
+ self ._sock = socket .socket (self .afi , socket .SOCK_STREAM )
308
307
309
308
for option in self .config ['socket_options' ]:
310
309
log .debug ('%s: setting socket option %s' , self , option )
@@ -328,10 +327,10 @@ def connect(self):
328
327
ret = None
329
328
try :
330
329
ret = self ._sock .connect_ex ((self .host , self .port ))
331
- # if we got here through a host lookup, we've found a host,port,af tuple
332
- # that works save it so we don't do a GAI lookup again
330
+ # if we got here through a host lookup,
331
+ # we've found a (host, port, af) tuple that works
332
+ # and we can stop iterating through the getaddrinfo list
333
333
if self ._gai is not None :
334
- self .afi = self ._sock .family
335
334
self ._gai = None
336
335
except socket .error as err :
337
336
ret = err .errno
0 commit comments