Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3305
  • Last Modified:

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?
0
arpanshah
Asked:
arpanshah
  • 2
  • 2
  • 2
  • +2
1 Solution
 
ser6398Commented:
You could create a job (using DBMS_JOB package) that kills the session, but it would not just halt the procedure.  I think you will find it difficult to just kill the procedure.

Given your setup, I would recommend that the external C function keep track of the time and return NULLs (or an error condition) back to the stored procedure if it has not received the info after 60 seconds.
0
 
arpanshahAuthor Commented:
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.
0
 
ser6398Commented:
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.
0
NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

 
jtriftsCommented:
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.

0
 
soraCommented:
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
0
 
soraCommented:
sorry, the step 3 should actually be step 2...:-)


sora
0
 
MoondancerCommented:
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.
0
 
jtriftsCommented:
recommend Points to ser6398.
regards,
JT
0
 
MoondancerCommented:
Thank you very much, JT, this has been finalized.
Moondancer - EE Moderator
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now