Skip to content

Commit

Permalink
[CLIENT] Do not duplicate connections in connection pool after rebuild (
Browse files Browse the repository at this point in the history
  • Loading branch information
deees authored and estolfo committed Jan 15, 2019
1 parent 8518d78 commit 16887e5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def __rebuild_connections(arguments={})

new_connections = __build_connections
stale_connections = @connections.all.select { |c| ! new_connections.include?(c) }
new_connections = new_connections.reject { |c| @connections.include?(c) }
new_connections = new_connections.reject { |c| @connections.all.include?(c) }

@connections.remove(stale_connections)
@connections.add(new_connections)
Expand Down
16 changes: 16 additions & 0 deletions elasticsearch-transport/test/unit/transport_base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,22 @@ def initialize(*); end
assert_equal 1, @transport.connections.size
assert_equal 1, @transport.connections.all.size
end

should "not duplicate connections" do
@transport.__rebuild_connections :hosts => [ { :host => 'node1', :port => 1 },
{ :host => 'node2', :port => 2 } ],
:options => { :http => {} }
assert_equal 2, @transport.connections.size

@transport.connections[0].dead!

@transport.__rebuild_connections :hosts => [ { :host => 'node1', :port => 1 },
{ :host => 'node2', :port => 2 } ],
:options => { :http => {} }

assert_equal 2, @transport.connections.all.size
assert_equal 1, @transport.connections.size
end
end

context "rebuilding connections" do
Expand Down

0 comments on commit 16887e5

Please sign in to comment.