Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Program dies

sharpesharpe Member Posts: 21
Hello,

I am having problems with a perl program crashing. I call the following method around 70,000 times:

sub do_request($$)
{
my ($request, $host, $socket, $data);
my %HEADERS;

$host = shift();
$request = shift();
$socket = IO::Socket::INET->new(PeerAddr => $host,
PeerPort => "http(80)",
Proto => "tcp") || die($!);

$request = "GET $request HTTP/1.0
";
$request .= "Accept: */*
";
$request .= "Accept-Language: da, en-gb, en-US
";
$request .= "Accept-Encoding: gzip, deflate
";
$request .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.0.3705)
";
$request .= "Host: $host
";
$request .= "Connection: Close


";
#print("$request
");
print($socket $request);
while ($data = <$socket>)
{
chomp($data);
if ($data =~ /^HTTP/1.ds(d{3})/) {
$HEADERS{_rc} = $1;
} elsif ($data =~ /^([a-z0-9_-]+):s*(.*)/i) {
$HEADERS{$1} = $2;
} else {
last();
}
}
shutdown($socket, 2);
return %HEADERS;
}

I get the following error after about 3,700 requests:
"Unknown error at vulfind.pl line 35."
Which is this line: $socket = IO::Socket::INET->new....
Do you have any ideas?


Thanks in advance!

Kindest regards,
sharpe

Comments

  • JonathanJonathan Member Posts: 2,914
    Hi,

    : I am having problems with a perl program crashing. I call the
    : following method around 70,000 times:
    :
    : ....tasty code....
    :
    : I get the following error after about 3,700 requests:
    : "Unknown error at vulfind.pl line 35."
    : Which is this line: $socket = IO::Socket::INET->new....
    : Do you have any ideas?
    Hmmmm...no! Well, I have ideas, just not explanation. I suspect it is specific to one or some of these:-
    1) Your platform
    2) Your version of IO::Socket::INET (try upgrading it?)
    3) Your version of Perl
    I've tried it on a Linux box conntecting to a locally running Apache and it notched up to the 50,000 mark before I closed it (way beyond your 3700). *many minutes later* My Windows box connecting to a remote server has reached a good way beyond 4000 and is still going strong. Looks like a tricky one to reproduce off your particular setup without deliberatly setting up the environment. And helpful as I like to try and be, I doubt I'm going to be able to set up something that mimics what you have closely enough, but try me.

    As for what we can do about it, why not just catch the exception and cause the function to return false if it fails?

    [code]eval {
    $socket = IO::Socket::INET->new(PeerAddr => $host,
    PeerPort => "http(80)",
    Proto => "tcp") || die($!);
    } or return 0;
    [/code]

    eval block catches the exception raised when die is called or the function fails. eval returns false rather than ture like it would on successful execution (normally or would short-circuit and not cause return 0) and thus you return a false value. You may be better returning undef perhaps? Not sure...

    Hope this helps somewhat - let me know if any deeper digging discovers you anything.

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • sharpesharpe Member Posts: 21
    Hi Jonathan,

    I just upgraded to 5.8.0 from 5.6.1 (up and down like a fidler's elbow..) and it seems as if, the problem has been solved.

    Thanks!
    Have a good weekend :-)
  • JonathanJonathan Member Posts: 2,914
    : I just upgraded to 5.8.0 from 5.6.1 (up and down like a fidler's
    : elbow..) and it seems as if, the problem has been solved.
    Interesting. Ah well, pleased it fixed it!

    : Have a good weekend :-)
    It's only Wednesday, but I sure will anyways. (Does this mean no more questions till next week? ;-))

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • sharpesharpe Member Posts: 21
    : : I just upgraded to 5.8.0 from 5.6.1 (up and down like a fidler's
    : : elbow..) and it seems as if, the problem has been solved.
    : Interesting. Ah well, pleased it fixed it!
    :
    : : Have a good weekend :-)
    : It's only Wednesday, but I sure will anyways. (Does this mean no more questions till next week? ;-))
    Hehe, it's a bank holiday today here in Denmark, so it's as good as the weekend :-)
    :
    : Jonathan
    :
    : ###
    : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    :
    :

  • JonathanJonathan Member Posts: 2,914
    [b][red]This message was edited by Jonathan at 2003-6-6 1:10:32[/red][/b][hr]
    : : : I just upgraded to 5.8.0 from 5.6.1 (up and down like a fidler's
    : : : elbow..) and it seems as if, the problem has been solved.
    : : Interesting. Ah well, pleased it fixed it!
    : :
    : : : Have a good weekend :-)
    : : It's only Wednesday, but I sure will anyways. (Does this mean no
    : : more questions till next week? ;-))
    : Hehe, it's a bank holiday today here in Denmark, so it's as good as
    : the weekend :-)
    It's alright for some! ;-)

    Weekend tomorrow...yes. And today is my last day at my current college...awwwwww. Just have to come back to take a few exams then I'm done.

    Ah well...more time to write Perl. :-)

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");



  • sharpesharpe Member Posts: 21
    I found the error (a very big DUHHH!):

    : Hello,
    :
    : I am having problems with a perl program crashing. I call the following method around 70,000 times:
    :
    : sub do_request($$)
    : {
    : my ($request, $host, $socket, $data);
    : my %HEADERS;
    :
    : $host = shift();
    : $request = shift();
    : $socket = IO::Socket::INET->new(PeerAddr => $host,
    : PeerPort => "http(80)",
    : Proto => "tcp") || die($!);
    :
    : $request = "GET $request HTTP/1.0
    ";
    : $request .= "Accept: */*
    ";
    : $request .= "Accept-Language: da, en-gb, en-US
    ";
    : $request .= "Accept-Encoding: gzip, deflate
    ";
    : $request .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.0.3705)
    ";
    : $request .= "Host: $host
    ";
    : $request .= "Connection: Close


    ";
    : #print("$request
    ");
    : print($socket $request);
    : while ($data = <$socket>)
    : {
    : chomp($data);
    : if ($data =~ /^HTTP/1.ds(d{3})/) {
    : $HEADERS{_rc} = $1;
    : } elsif ($data =~ /^([a-z0-9_-]+):s*(.*)/i) {
    : $HEADERS{$1} = $2;
    : } else {
    : last();
    : }
    : }
    : shutdown($socket, 2);
    #### HERE it is: I am not returning a hash but rather a scalar!!
    : return %HEADERS;
    : }
    :
    : I get the following error after about 3,700 requests:
    : "Unknown error at vulfind.pl line 35."
    : Which is this line: $socket = IO::Socket::INET->new....
    : Do you have any ideas?
    :
    :
    : Thanks in advance!
    :
    : Kindest regards,
    : sharpe
    :

Sign In or Register to comment.