Skip to content

Commit

Permalink
reuse same object after calling purge_obsolete_socks
Browse files Browse the repository at this point in the history
since @available_sockets is initialized with
`Hash.new { |obj, k| obj[k] = [] }` at https://github.com/fluent/fluentd/blob/v1.7.1/lib/fluent/plugin/out_forward/socket_cache.rb#L27

Signed-off-by: Yuta Iwama <[email protected]>
  • Loading branch information
ganmacs committed Sep 30, 2019
1 parent 497fd28 commit 0e81244
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/fluent/plugin/out_forward/socket_cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ def purge_obsolete_socks
end
end
end
@available_sockets = @available_sockets.select { |_, v| !v.empty? }

# reuse same object (@available_sockets)
@available_sockets.reject! { |_, v| v.empty? }

sockets += @inactive_sockets
@inactive_sockets.clear
Expand Down
11 changes: 11 additions & 0 deletions test/plugin/out_forward/test_socket_cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ class SocketCacheTest < Test::Unit::TestCase
sock = mock!.open { new_sock }.subject
assert_equal(new_sock, c.checkout_or('key') { sock.open })
end

test 'reuse same hash object after calling purge_obsolete_socks' do
c = Fluent::Plugin::ForwardOutput::SocketCache.new(10, $log)
socket = 'socket'
c.checkout_or('key') { socket } # cached
c.purge_obsolete_socks

assert_nothing_raised(NoMethodError) do
c.checkout_or('key') { 'new soeckt' }
end
end
end

sub_test_case 'checkin' do
Expand Down

0 comments on commit 0e81244

Please sign in to comment.