Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Help on crash in sleep() !

by pcouderc (Monk)
on Oct 23, 2015 at 17:53 UTC ( [id://1145791]=perlquestion: print w/replies, xml ) Need Help??

pcouderc has asked for the wisdom of the Perl Monks concerning the following question:

I have a service under Ubuntu wich usually works very fine. Except after a few hours, where it crashes in sleep() ! Here is the portion of code :
my $log = Log::Log4perl->get_logger("wiftv"); ... $log->debug("waittime $waittime"); sleep($waittime); $log->debug("end loop");
The log ends with :
... [2015/10/23 19:41:29] DEBUG wiftv - waittime 60
Thank you for any idea, o monks. PC

Replies are listed 'Best First'.
Re: Help on crash in sleep() !
by Corion (Patriarch) on Oct 23, 2015 at 17:55 UTC

    sleep can be interrupted by signals. Maybe your code (or some (C) library it uses) doesn't handle an incoming signal in a good way and the process ends that way?

    Can you structure your process in a way that it can be easily restarted by a wrapping shell script or simply reimplement it as a cron job that is run every minute?

      It seems to me that a signal would be possible only if the process would be expecting something, if we were in multithread. This is not the case. We wait 1 minute before checking new work to do. It a simple "polling". Yes it would be possible to wrap it in a main script, but I would like to understand.

        Have you read the documentation link I provided?

        May be interrupted if the process receives a signal such as SIGALRM .

        So, if anything sends a signal to your process, such as SIGALRM, it might wake up or crash.

Re: Help on crash in sleep() !
by ikegami (Patriarch) on Oct 23, 2015 at 18:31 UTC
    What's the process's exit code?
      Good idea, but I do not know how to do that for a service ?
Re: Help on crash in sleep() !
by NetWallah (Canon) on Oct 24, 2015 at 03:22 UTC
    Here another consideration (with a low probability of being right):

    What if there is a log file error, Log module error, or disk full condition ?

            The best defense against logic is ignorance.

      Good idea, but the disk is not full and log4perl continues to work on another process...
Re: Help on crash in sleep() !
by Anonymous Monk on Oct 23, 2015 at 22:58 UTC
    Then ... it got interrupted by a signal, and did not trap that signal, and died silently.
Re: Help on crash in sleep() !
by sundialsvc4 (Abbot) on Oct 23, 2015 at 19:29 UTC

    In perldoc sleep, we read the following caveats:

    May be interrupted if the process receives a signal such as "SIGALRM".
    eval { local $SIG{ALARM} = sub { die "Alarm!\n" }; sleep; }; die $@ unless $@ eq "Alarm!\n";
    You probably cannot mix "alarm" and "sleep" calls, because "sleep" is often implemented using "alarm."

    Methinks that some or all of the foregoing will prove to have exceptional relevance to your present problem.   ...

    In fact, I would wager that it consists of what has been described here:   “sleeps can be interrupted by a signal, and ‘un-caught signals’ generally mean ... (oopsie! hateitwhenthishappens!!) ... Death.”

    However, not to be “snarky,” tell us more!   When your script runs into trouble, what does it do?   What does it log?   The more specific detail you can give, the more specifically we can help you ... and, after all, that’s why we’re all here.

      Please see my answer above for alarms.
      In fact I do not know what it does.
      It is no more present, and I do not know how and why it stops. And I have displayed the log above. It starts sleep, then disappears without logging more...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1145791]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (2)
As of 2024-04-26 06:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found