Skip to content

Commit fbda940

Browse files
committed
fix contact resolution
1 parent 8b9dac0 commit fbda940

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

cassandra/cluster.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,19 @@ def default_lbp_factory():
192192
return DCAwareRoundRobinPolicy()
193193

194194

195+
def _addrinfo_or_none(contact_point, port):
196+
"""
197+
A helper function that wraps socket.getaddrinfo and returns None
198+
when it fails to, e.g. resolve one of the hostnames. Used to address
199+
PYTHON-895.
200+
"""
201+
try:
202+
return socket.getaddrinfo(contact_point, port,
203+
socket.AF_UNSPEC, socket.SOCK_STREAM)
204+
except (socket.error, socket.herror, socket.gaierror, socket.timeout):
205+
return None
206+
207+
195208
class ExecutionProfile(object):
196209
load_balancing_policy = None
197210
"""
@@ -824,8 +837,12 @@ def __init__(self,
824837

825838
self.port = port
826839

827-
self.contact_points_resolved = [endpoint[4][0] for a in self.contact_points
828-
for endpoint in socket.getaddrinfo(a, self.port, socket.AF_UNSPEC, socket.SOCK_STREAM)]
840+
self.contact_points_resolved = [
841+
endpoint[4][0]
842+
for point in self.contact_points
843+
for endpoint in _addrinfo_or_none(point, self.port)
844+
if endpoint is not None
845+
]
829846

830847
self.compression = compression
831848

0 commit comments

Comments
 (0)