Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion lib/fluent/plugin_helper/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,10 @@ def stop
end

def shutdown
@_server_connections.each do |conn|
# When it invokes conn.cose, it reduces elements in @_server_connections by close_callback,
# and it reduces the number of loops. This prevents the connection closing.
# So, it requires invoking #dup to avoid the problem.
@_server_connections.dup.each do |conn|
conn.close rescue nil
end

Expand Down
19 changes: 19 additions & 0 deletions test/plugin_helper/test_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,25 @@ class Dummy < Fluent::Plugin::TestBase
d2.stop; d2.before_shutdown; d2.shutdown; d2.after_shutdown; d2.close; d2.terminate
end
end

test 'close all connections by shutdown' do
@d.server_create_tcp(:s, @port) do |data, conn|
end

client_sockets = []
5.times do
client_sockets << TCPSocket.open("127.0.0.1", @port)
end
waiting(4){ sleep 0.1 until @d.instance_variable_get(:@_server_connections).size == 5 }

@d.stop
@d.before_shutdown
@d.shutdown

assert_true @d.instance_variable_get(:@_server_connections).empty?
ensure
client_sockets.each(&:close)
end
end

sub_test_case '#server_create' do
Expand Down
Loading