Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions faktory/_proto.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,21 @@ def connect(self, worker_id=None) -> bool:
self.log.info("Connecting to {}:{}".format(self.host, self.port))
self.is_connecting = True

self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# handle IPv4 or IPv6 hosts, get addr info returns a list of tuples of tuples
# this always uses the first one
faktory_ip_addresses = socket.getaddrinfo(self.host, None)
faktory_ip_address = faktory_ip_addresses[0][4][0]
faktory_ip_address_faimly = faktory_ip_addresses[0][0]

self.socket = socket.socket(faktory_ip_address_faimly, socket.SOCK_STREAM)
if self.use_tls:
self.log.debug("Using TLS")
self.socket = ssl.wrap_socket(self.socket)

self.socket.setblocking(0)
self.socket.settimeout(self.timeout)
try:
self.socket.connect((self.host, self.port))
self.socket.connect((faktory_ip_address, self.port))
except ssl.SSLError:
raise

Expand Down