Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add compatibility for Ipv6 address #138

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 3 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
14 changes: 13 additions & 1 deletion fluent/sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ def close(self):
self._close()
self.pendings = None

def _is_ipv6_host(self):
try:
socket.getaddrinfo(self.host, None, socket.AF_INET6)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will result in host that has AAAA records to prefer AF_INET6 even if AF_INET IPv4 addresses are available. This is not the current behavior and will potentially break tons of stuff for people who are not expecting this behavior.

return True
except socket.error:
return False

def _make_packet(self, label, timestamp, data):
if label:
tag = '.'.join((self.tag, label))
Expand Down Expand Up @@ -203,7 +210,12 @@ def _reconnect(self):
sock.settimeout(self.timeout)
sock.connect(self.host[len('unix://'):])
else:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
if self._is_ipv6_host():
sock = socket.socket(socket.AF_INET6,
socket.SOCK_STREAM)
else:
sock = socket.socket(socket.AF_INET,
socket.SOCK_STREAM)
sock.settimeout(self.timeout)
# This might be controversial and may need to be removed
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
Expand Down