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

how to prevent perl script from terminating

by kamrul (Acolyte)
on May 20, 2015 at 17:12 UTC ( [id://1127255]=perlquestion: print w/replies, xml ) Need Help??

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

Hi, I am using a library(Net::APNS::Persistent) that uses Net::SSLeay library for establishing SSL connection with Apples APNS servers. Apple server closes session if a wrong token is supplied. But, my problem is the Net::SSLeay library is terminating my program when the connection is dropped by Apple server.

As per my debugging this issue is occurring from line number 1895 of SSLeay.pm

 $wrote = write_partial($ssl, $written, $to_write, $$data_ref);

I tried to catch if any exception, term signal were sent but no luck. If there is a network issue or any sort of error I expect it should show an error message/ exception that can be handled. But it simply kills the program without saying anything. So, how can I prevent write_partial() function from terminating my program ?

Replies are listed 'Best First'.
Re: how to prevent perl script from terminating
by t_rex_joe (Sexton) on May 20, 2015 at 17:44 UTC
    You can use "eval" around the code..
    while (1) { $wrote = undef; eval { $wrote = write_partial($ssl, $written, $to_write, $$data_ref) +; 1; } or do { print "WRITE PARTIAL FAILED L: \"" . __LINE__ . "\"\n"; sle +ep 3; next; } if(defined $wrote) { print "WROTE: \"$wrote\". LAST L: \"" . __LINE__ . "\"\n"; last; } else { print "DO NOT KNOW HOW I GOT HERE WROTE: \"$wrote\". LAST L: + \"" . __LINE__ . "\"\n"; } } #EO WHILE
    Joe
      Hi thanks for your reply. Im going to try that. One small question. Can you please explain why you are using the loop around the code ?

      Thanks in advanced ..

        The loop will keep trying the write_partial until it succeeds.

        Dum Spiro Spero
        Just tried like the below :
        eval{ $wrote = write_partial($ssl, $written, $to_write, $$data_ref); }; print "Write error $@" if $@;
        But no luck! the script is terminating showing no error. Is there anything else I can try ?
Re: how to prevent perl script from terminating
by Anonymous Monk on May 20, 2015 at 18:47 UTC

    You've ruled out signals then? Did you try catch or ignore as with $SIG{PIPE} = 'IGNORE'; ?

      Hi, I didnt try with: $SIG{'PIPE'} = 'IGNORE' before. Now I can prevent it from stopping and catch the exceptions aswell ... Thanks a lot!!!
Re: how to prevent perl script from terminating
by GotToBTru (Prior) on May 20, 2015 at 18:33 UTC

    The problem is probably not that a particular line in NET::SSLeay fails, but rather that line is part of a method that assumes the connection is still intact. I think that is probably your job: test to make sure the connection is still active before attempting to execute this method in the NET::SSLeay package.

    Dum Spiro Spero

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (8)
As of 2024-04-23 12:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found