Subject: | Possible Bug Report: Round Robin DNS |
Date: | Thu, 2 Mar 2017 16:32:26 -0600 |
To: | bug-Crypt-SSLeay [...] rt.cpan.org |
From: | Jake Cloyd <dyolcekaj [...] gmail.com> |
Hello,
In the "connect()" subroutine of Net::SSL.pm when a connection can't be
made the code currently croaks on line 114
else {
*$self->{io_socket_peername}=@_ == 1 ? $_[0] :
IO::Socket::sockaddr_in(@_);
if(!$self->SUPER::connect(@_)) {
# better to die than return here
$@ = "Connect failed: $@; $!";
croak($@);
}
}
When gethostbyname() returns multiple IP addresses and the first
"connect()" attempt results in failure the croak will kill the
iterating code. IO::Socket::INET.pm will iterate over
gethostbyname()'s output and die in this scenario before attempting
the second IP. We were seeing intermittent failures when one of the
IPs a hostname would resolve to was unreachable.
To fix this in our application connect() will return undef instead of
croaking in a modified Net:SSL.pm file.
else {
*$self->{io_socket_peername}=@_ == 1 ? $_[0] :
IO::Socket::sockaddr_in(@_);
if(!$self->SUPER::connect(@_)) {
$@ = "Connect failed: $@; $!";
return undef;
#croak($@);
}
}
Here is basically the code we were running. To reproduce you need to
have a round robin DNS entry with one of the IPs being bogus and run
something similar to the below.
@LWP::Protocol::http::EXTRA_SOCK_OPTS = (
MultiHomed => 1,
);
my $useragent = LWP::UserAgent->new;
## build request
my $response = $useragent->request($request);
Thanks,
Jake Cloyd