Skip to content

Commit 2c2a277

Browse files
jonhymanp
authored andcommitted
Fix RUBY-2030 Client/Cluster construction fails when duplicate seed addresses are provided (#1594)
* Ensure that a duplicate host entry won't prevent a Cluster from instantiating. * Some pull request updates for tests. * Disconnect monitoring threads. * Use register_cluster.
1 parent d15894e commit 2c2a277

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

lib/mongo/cluster.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ def initialize(seeds, monitoring, options = Options::Redacted.new)
109109
options[:cleanup] = false
110110
end
111111

112+
seeds = seeds.uniq
113+
112114
@servers = []
113115
@monitoring = monitoring
114116
@event_listeners = Event::Listeners.new

spec/mongo/cluster_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,25 @@
2020

2121
let(:cluster) { cluster_without_io }
2222

23+
describe 'initialize' do
24+
25+
context 'when there are duplicate addresses' do
26+
27+
let(:addresses) do
28+
SpecConfig.instance.addresses + SpecConfig.instance.addresses
29+
end
30+
let(:cluster_with_dup_addresses) do
31+
register_cluster(
32+
described_class.new(addresses, monitoring, SpecConfig.instance.test_options))
33+
end
34+
35+
it 'does not raise an exception' do
36+
expect { cluster_with_dup_addresses }.not_to raise_error
37+
end
38+
end
39+
40+
end
41+
2342
describe '#==' do
2443

2544
context 'when the other is a cluster' do

0 commit comments

Comments
 (0)