Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

SIGALRM in perl

by anjultyagi (Novice)
on Jan 15, 2019 at 11:24 UTC ( #1228585=perlquestion: print w/replies, xml ) Need Help??
anjultyagi has asked for the wisdom of the Perl Monks concerning the following question:

Hi Expert, I am using the PERL language with the PostgreSQL database and in a couple of database function, we are using the plperl as language. We are basically calling the SOAP API in the function, however yesterday we faced the issue where PARL had sent the SIGALRM signal and my database got crashed. Can you please review and help me to resolve the issue, either by a code change or a configuration change.

CREATE OR REPLACE FUNCTION sendclaimcoversheet( text, text) RETURNS integer AS $BODY$ use strict; use warnings; use SOAP::Lite; use Try::Tiny; use Time::Piece; my $first = $_[0]; my $second = $_[1]; try { my $host = `hostname`; my $rv = spi_exec_query("select * from getsprocurl('sendclaimc +oversheet','".$host."')"); my $url = $rv->{rows}[0]->{ret_url}; elog(NOTICE, 'Host Name ' . $host . ' URL '. $url ); my $soap = SOAP::Lite->new(); my $service = $soap->service($url); my $response = $service->sendClaimCoversheet($first, $second +); return $response; } catch { my $ex = $_; return 'SOAPFAULT: ' . localtime->strftime('%m/%d/%Y') . ' ' . + $ex; } $BODY$ LANGUAGE plperlu VOLATILE STRICT COST 100; ALTER FUNCTION sendclaimcoversheet(text, text) OWNER TO postgres;

Replies are listed 'Best First'.
Re: SIGALRM in perl
by shmem (Chancellor) on Jan 15, 2019 at 19:49 UTC
    Hi Expert, I am using the PERL language with the PostgreSQL (...) however yesterday we faced the issue where PARL had sent the SIGALRM signal

    First, to nitpick a bit, The Language is called "Perl" while the binary is called "perl" or "perl.exe", but that's just flavours. End of nitpick.

    Most likely, your embedded perl procedure got a SIGALRM from somwhere else, terminated, and sent that signal upstream where you could see it. In your code, there isn't anything handling an ALARM signal. To debug, set $SIG{ALRM} to some subroutine which reports its arguments, probably along with other stuff, like timestamps or the state of some (global or local) variables or structures:

    CREATE OR REPLACE FUNCTION sendclaimcoversheet( text, text) RETURNS integer AS $BODY$ use strict; use warnings; use SOAP::Lite; use Try::Tiny; use Time::Piece; local $SIG{ALRM} = sub { die "function sendclaimcoversheet caught ALRM with:\n(", join( ",",@_)),")\n"; };

    You should see the message "function sendclaimcoversheet caught ALRM" in the place where STDERR is collected. Go on from there.

    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

      Hi Shmem, Can we figure out why process received the SIGALRM any specific reason for that? If we handle that signal can we raise an exception and override the default operations.

        Can we figure out why process received the SIGALRM any specific reason for that?

        You might try strace, e.g. strace -e trace=signal,alarm ..., but typically, SIGALRM is arranged by alarm (in Perl, alarm). (Update: Also note that "sleep may be internally implemented on your system with alarm.")

        If we handle that signal can we raise an exception and override the default operations.

        Yes, by setting a %SIG handler as shmem showed above. But I would recommend first trying to figure out where the signal is coming from in the first place.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2019-02-19 22:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I use postfix dereferencing ...









    Results (105 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!