File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed
Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -356,7 +356,10 @@ def stop
356356 end
357357
358358 def shutdown
359- @_server_connections . each do |conn |
359+ # When it invokes conn.cose, it reduces elements in @_server_connections by close_callback,
360+ # and it reduces the number of loops. This prevents the connection closing.
361+ # So, it requires invoking #dup to avoid the problem.
362+ @_server_connections . dup . each do |conn |
360363 conn . close rescue nil
361364 end
362365
Original file line number Diff line number Diff line change @@ -381,6 +381,24 @@ class Dummy < Fluent::Plugin::TestBase
381381 d2 . stop ; d2 . before_shutdown ; d2 . shutdown ; d2 . after_shutdown ; d2 . close ; d2 . terminate
382382 end
383383 end
384+
385+ test 'close all connections by shutdown' do
386+ @d . server_create_tcp ( :s , @port ) do |data , conn |
387+ end
388+
389+ client_sockets = [ ]
390+ 5 . times do
391+ client_sockets << TCPSocket . open ( "127.0.0.1" , @port )
392+ end
393+ waiting ( 4 ) { sleep 0.1 until @d . instance_variable_get ( :@_server_connections ) . size == 5 }
394+
395+ @d . before_shutdown
396+ @d . shutdown
397+
398+ assert_true @d . instance_variable_get ( :@_server_connections ) . empty?
399+
400+ client_sockets . each ( &:close )
401+ end
384402 end
385403
386404 sub_test_case '#server_create' do
You can’t perform that action at this time.
0 commit comments