Skip to content

Commit 6f9b0b0

Browse files
valentin benozillomcipperly
valentin benozillo
authored andcommitted
Add compatibility for Ipv6 address
Signed-off-by: Matt Cipperly <[email protected]>
1 parent ace80f4 commit 6f9b0b0

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

fluent/sender.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,13 @@ def close(self):
120120
self._close()
121121
self.pendings = None
122122

123+
def _is_ipv4_host(self):
124+
try:
125+
socket.getaddrinfo(self.host, None, socket.AF_INET)
126+
return True
127+
except socket.error:
128+
return False
129+
123130
def _make_packet(self, label, timestamp, data):
124131
if label:
125132
tag = '.'.join((self.tag, label))
@@ -201,7 +208,12 @@ def _reconnect(self):
201208
sock.settimeout(self.timeout)
202209
sock.connect(self.host[len('unix://'):])
203210
else:
204-
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
211+
if self._is_ipv4_host():
212+
sock = socket.socket(socket.AF_INET,
213+
socket.SOCK_STREAM)
214+
else:
215+
sock = socket.socket(socket.AF_INET6,
216+
socket.SOCK_STREAM)
205217
sock.settimeout(self.timeout)
206218
# This might be controversial and may need to be removed
207219
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)

0 commit comments

Comments
 (0)