in reply to Fetching Madness

Perl 5.8 should support ALRM even on Windows. To verify that, here is some simple code: This should just print nonsense for one second (could be a lot of lines if your processor is fast), but should die with an error message if $SIG{ALRM} is working on your platform. This program works on a Linux Perl 5.8 system and Windows Perl 5.10. I don't have a Windows Perl 5.8 system to test with.
!/usr/bin/perl -w use strict; $| =1; #turns off output buffering #without this the "die" message might not be #seen due to STDOUT buffering $SIG{ALRM} = 'alarmhander'; alarm(1); while (1) { print "blah...anything..lot's of lines\n"; } sub alarmhander { die "ooops bailing out with die\n" }

Replies are listed 'Best First'.
Re^2: Fetching Madness
by jlongino (Parson) on Mar 09, 2009 at 14:29 UTC
    The author (Lincoln A Baxter) of the article I linked above explains that beginning with Perl 5.8.0, the $SIG{ALRM} doesn't work as it previously did, that the code just hangs. At least as it relates to connects and long running statements attempting to communicate with Oracle.

    I have not had the time to test his assertion, but have given him the benefit of the doubt. I also hesitate to quote directly from his article, though I imagine since it is on the site, it might not be an issue.

    Since the code you posted is minimal, I will test it and relay the results here.

Re^2: Fetching Madness
by jlongino (Parson) on Mar 11, 2009 at 20:34 UTC
    It looks as though Lincoln A Baxter was right about the Perl 5.8.0 SIG ALRT situation. I modified my code to time out, and it did--until I realized it only times out correctly if the program hasn't "hung" yet. After setting the timeout to 60 seconds for example, the program hangs before the 60 second limit and the timeout won't occur.

    Next I'll test the Sys::SigAction solution to see if it works.

Re^2: Fetching Madness
by jlongino (Parson) on Mar 12, 2009 at 15:08 UTC
    Success on two fronts! The systems people discovered that the problem was due to a change in the firewall code. Something to do with deep packet inspection and differing buffer sizes.

    I had already gotten far enough along with the Sys::SigAction testing to find that it does work. I was about to post some code but it is practically verbatim to the examples in the link included in my first post above. I'm going to implement Sys:SigAction in my programs from now on to prevent the occurrence of perpetual hangs.

      Fantastic! I did some looking at this also. The problem is with deferred action on some signals and appears to be Perl version specific., eg Perl 5.8.2 will work differently than 5.8.0 and Perl 5.8.0 is different than Perl 5.6.x. The POSIX way >=Perl 5.8.2 is much better than the 5.6 way since you can do something other than just "blow up". There appears to be a way to "have your cake and eat it too" on more recent versions of Perl (apparently you can set the "safe" flag so that Perl checks ALRM often enough that the program won't hang). On the other hand, "blow up" is often the correct answer to something like "cannot connect to the DB".

      Anyway programming is often pragmatic and you have do just do what works! If that means reverting to 5.6 style signal handling to cover all versions of Perl you work with, so be it!