Skip to content
This repository has been archived by the owner on Dec 22, 2021. It is now read-only.

Commit

Permalink
Fix dup connection port weirdness PERL-158
Browse files Browse the repository at this point in the history
  • Loading branch information
kchodorow committed Jan 24, 2012
1 parent 8abebe1 commit f05a70f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
5 changes: 4 additions & 1 deletion Changes
Expand Up @@ -2,7 +2,10 @@

- Added SSL support (Casey Rojas)

- Fix auth (Olly Stephens)
- Fix auth connection issues (Olly Stephens)

- Fix driver creating duplicate connections when port isn't specified (Olly
Stephens)

0.45 - September 7, 2011

Expand Down
14 changes: 8 additions & 6 deletions lib/MongoDB/Connection.pm
Expand Up @@ -463,17 +463,13 @@ sub BUILD {
# supported syntax
else {
my $str = substr $self->host, 10;
@pairs = split ",", $str;
@pairs = map { $_ .= ":27017" unless $_ =~ /:/ ; $_ } split ",", $str;
}

# a simple single server is special-cased (so we don't recurse forever)
if (@pairs == 1 && !$self->find_master) {
my @hp = split ":", $pairs[0];

if (!exists $hp[1]) {
$hp[1] = 27017;
}

$self->_init_conn($hp[0], $hp[1], $self->ssl);
if ($self->auto_connect) {
$self->connect;
Expand Down Expand Up @@ -659,9 +655,15 @@ sub get_master {
# if this is a replica set & we haven't renewed the host list in 1 sec
if ($master->{'hosts'} && time() > $self->ts) {
# update (or set) rs list
my %opts = ( auto_connect => 0 );
if ($self->username && $self->password) {
$opts{username} = $self->username;
$opts{password} = $self->password;
$opts{db_name} = $self->db_name;
}
for (@{$master->{'hosts'}}) {
if (!$self->_servers->{$_}) {
$self->_servers->{$_} = MongoDB::Connection->new("host" => "mongodb://$_", auto_connect => 0);
$self->_servers->{$_} = MongoDB::Connection->new("host" => "mongodb://$_", %opts);
}
}
$self->ts(time());
Expand Down

0 comments on commit f05a70f

Please sign in to comment.