Link to home
Start Free TrialLog in
Avatar of arpanshah
arpanshah

asked on

Pl/SQL Procedure timeout

I have a PL/SQL procedure that calls an external C function. The external C function has a socket interface to another program and waits to receive information on the socket. After receiving the information it passes the information back to the procedure by reference variables. However, I want to setup a timeout on my PL/SQL procedure so that after 60 seconds, if it doesn't return any values to me I can kill the procedure. Is there any way to implement timeouts in my PL/SQL procedure?
ASKER CERTIFIED SOLUTION
Avatar of ser6398
ser6398

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of arpanshah
arpanshah

ASKER

The C function I have calls the socket recv() function which just waits till it gets some info over the socket. I cannot implement a timeout there cause I have no control over the socket recv() function.

Does, PL/SQL allow implementing timeouts in anyway? The problem is i could have several different instances of this procedure running at the same time and right now the database CPU just shoots up since the process is waiting infinitely to get a response.

Any other suggestions?

Thanks.
C functions allow threads.  You could create a thread to call the socket.  If the thread doesn't respond within 60 seconds, the main program could kill the thread.

This type of advanced programming is not available in a PL/SQL program.  You have many more options available to you in C than PL/SQL.

The only other way I can think of to do this would be to create a separate procedure that runs in a different session.  The main procedure could communicate with the second procedure through DBMS_PIPE.  The second procedure would call the C program.  If it doesn't respond back within 60 seconds, the main procedure could kill the session of the second procedure.  Sounds complex, but I think it could work.

When it comes down to it, C is a much more advanced programming language than PL/SQL, giving you more options.  Since you are already going through a C program, I recommend that you put this type of advanced stuff in the C program instead of in PL/SQL.
Avatar of jtrifts
In terms of PL/SQL, there is already a pre-defined exception called TIMEOUT_ON_RESOURCE (Ora-00051 SQLCODE -51).  

Speak to your DBA...you may be able to set the applicable DB value for this and use a WHEN TIMEOUT_ON_RESOURCE exception handler in your procedure.

You can use Oracle AQ for this kind of async requirement.

1. create a AQ
3. A Pro*C program periodically looks at the queue or stays eternally connected to the queue (This is not polling! The AQ will push info to the recipient)

This Pro*C program can then get info from the socket and place it into a queue from where the pl/sql procedure will pick it up.

This is easy to set up and maintain.

AQ can provide you with timeouts, expiry of messages placed in the queues, delay times etc.


sora
sorry, the step 3 should actually be step 2...:-)


sora
Please update and finalize this old, open question.  Please:

1) Award points ... if you need Moderator assistance to split points, comment here with details please or advise us in Community Support with a zero point question and this question link.
2) Ask us to delete it if it has no value to you or others
3) Ask for a refund so that we can move it to our PAQ at zero points if it did not help you but may help others.

EXPERT INPUT WITH CLOSING RECOMMENDATIONS IS APPRECIATED IF ASKER DOES NOT RESPOND.

Thanks,
Moondancer - EE Moderator

P.S.  Please click your Member Profile, expand View Question History to navigate and update all your open and locked questions.
recommend Points to ser6398.
regards,
JT
Thank you very much, JT, this has been finalized.
Moondancer - EE Moderator