develooper Front page | perl.libwww | Postings from May 2013

is IO:Socket:INET thread safe?

Thread Next
From:
Jesper Persson
Date:
May 29, 2013 06:17
Subject:
is IO:Socket:INET thread safe?
Message ID:
CA+uC3V1X1hmk5Kpmwj0WvYviqx5Ze0A2BfONEvTxDowcb1Q8bA@mail.gmail.com
Hi everybody,

I have a multithreaded program that monitors the content of web pages.
On a newly installed CentOS server I have seen strange behaviour where I
get 404 because http request is sent to a wrong ip address not maching the
domain that was requested.

I have inserted a print statement in IO:Socket:INET.pm in the procedure
_get_addr
to see what ip address the domain is translated to:

sub _get_addr {
    my($sock,$addr_str, $multi) = @_;
    my @addr;
    if ($multi && $addr_str !~ /^\d+(?:\.\d+){3}$/) {
        (undef, undef, undef, undef, @addr) = gethostbyname($addr_str);
    } else {
        my $h = inet_aton($addr_str);
        push(@addr, $h) if defined $h;
    }
    open(FH, ">>/tmp/socket_get_addr.log");
    print FH localtime().": addr_str: $addr_str, addr:
".inet_ntoa($addr[0])."\n";
    close(FH);
    @addr;
}

From the log file:
Wed May 29 07:38:09 2013: addr_str: dk1.siteimprove.com, addr: 93.160.60.57
Wed May 29 07:38:09 2013: addr_str: siteimprove.dk, addr: 93.160.60.57

the ip address of siteimprove.dk is wrong and at the same second just
before a lookup of dk1.siteimprove.com gets the same ip address and that is
correct.

7 minutes later in the log file the siteimprove.dk domain is looked up
correctly:
Wed May 29 07:45:11 2013: addr_str: siteimprove.dk, addr: 93.160.60.87

Manually looking up the ip on then server gets the right ip address.

this entry is in the hosts file:
93.160.60.87        siteimprove.dk

CentOS release 6.3 (Final)
Summary of my perl5 (revision 5 version 10 subversion 1) configuration:
IO:Socket:INET version: $VERSION = "1.31";

Any help would be greatly appreciated.

Regards
Jesper Persson

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About