Skip to content

Commit

Permalink
Merge pull request #2697 from fluent/fix-dual-stack-ipv6-issue
Browse files Browse the repository at this point in the history
server helper: Fix IPv6 dual stack mode issue for tcp socket.
  • Loading branch information
repeatedly authored Nov 15, 2019
2 parents e1c8ed5 + 29b5176 commit 39e8b77
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/fluent/plugin_helper/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,11 @@ def server_create_tcp_socket(shared, bind, port)
sock = if shared
server_socket_manager_client.listen_tcp(bind, port)
else
TCPServer.new(bind, port) # this method call can create sockets for AF_INET6
# TCPServer.new doesn't set IPV6_V6ONLY flag, so use Addrinfo class instead.
# backlog will be set by the caller, we don't need to set backlog here
tsock = Addrinfo.tcp(bind, port).listen
tsock.autoclose = false
TCPServer.for_fd(tsock.fileno)
end
# close-on-exec is set by default in Ruby 2.0 or later (, and it's unavailable on Windows)
sock.fcntl(Fcntl::F_SETFL, Fcntl::O_NONBLOCK) # nonblock
Expand Down
13 changes: 13 additions & 0 deletions test/plugin_helper/test_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,19 @@ class Dummy < Fluent::Plugin::TestBase
assert_equal ["yayfoo\n", "yayfoo\n", "yayfoo\n"], lines
assert_equal ["closed", "closed", "closed"], callback_results
end

test 'can listen IPv4 / IPv6 together' do
omit "IPv6 unavailable here" unless ipv6_enabled?

assert_nothing_raised do
@d.server_create_tcp(:s_ipv4, PORT, bind: '0.0.0.0', shared: false) do |data, conn|
# ...
end
@d.server_create_tcp(:s_ipv6, PORT, bind: '::', shared: false) do |data, conn|
# ...
end
end
end
end

sub_test_case '#server_create_udp' do
Expand Down

0 comments on commit 39e8b77

Please sign in to comment.