The program has been running for more than 10 years without this beeing an issue - at least I have never been aware of this kind of problem. Perhaps I only first see it now on the new server because the server is a virtual machine and maybe doesn't have a dedicate cpu and more often will get interrupts on the cpu.
The reason that the program uses processes is that is has a mother process fetching work from the database and communicating the work/result of the work to/from the threads via Thread::Queue. Am I the first one using threads doing http requests in perl on linux having this problem? Seems odd. If I would change my program to using processes instead of threads, would gethostbyname then be process safe? It looks as if gethostbyname has a version that is reentrant: gethostbyname_r. Any reason that perl doesn't use that version? Regards On 29 May 2013 10:12, Francesco Nidito <francesco.nid...@gmail.com> wrote: > Unfortunately, gethostbyname is not reentrant. > > (maybe a stupid question) Is there any particular reason why you cannot > use multiple processes instead? > > Typed on a very small keyboard... > ------------------------------ > From: Jesper Persson <jesper.j.pers...@gmail.com> > Sent: 29/05/2013 07:17 > To: libwww <libwww@perl.org> > Subject: is IO:Socket:INET thread safe? > > 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 >