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

is IO:Socket:INET thread safe?

Thread Next
Jesper Persson
May 29, 2013 06:17
is IO:Socket:INET thread safe?
Message ID:
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 in the procedure
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:

From the log file:
Wed May 29 07:38:09 2013: addr_str:, addr:
Wed May 29 07:38:09 2013: addr_str:, addr:

the ip address of is wrong and at the same second just
before a lookup of gets the same ip address and that is

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

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

this entry is in the hosts file:

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.

Jesper Persson

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About