diff --git a/elasticsearch-transport/lib/elasticsearch/transport/transport/base.rb b/elasticsearch-transport/lib/elasticsearch/transport/transport/base.rb index c82867edb7..e87b4d89d1 100644 --- a/elasticsearch-transport/lib/elasticsearch/transport/transport/base.rb +++ b/elasticsearch-transport/lib/elasticsearch/transport/transport/base.rb @@ -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) diff --git a/elasticsearch-transport/test/unit/transport_base_test.rb b/elasticsearch-transport/test/unit/transport_base_test.rb index 0d98867b99..124b9ed517 100644 --- a/elasticsearch-transport/test/unit/transport_base_test.rb +++ b/elasticsearch-transport/test/unit/transport_base_test.rb @@ -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