Print Thread
Page 1 of 3 1 2 3
Application crash without exception on LogOff when busy
#6101 02/27/04 04:33 PM
Joined: Feb 2004
Posts: 41
R
Ralf Offline OP
Member
OP Offline
Member
R
Joined: Feb 2004
Posts: 41
Situation:
Table LOCKTEST with unique field TESTID.

From one session (for example SQL+) insert a record with TESTID=33 without commit.

Then from Delphi application with thread having a TOracleQuery do the same (insert record with TESTID=33). Then this thread hangs until the other session is committed.

If you don't commit the other thread and call OracleSession.LogOff in the hanging thread the application wil crash without any exception! The last debug line is a call to 'OCISessionEnd'.

Calling BreakExecution first doesn't make a difference.

Any ideas?

Re: Application crash without exception on LogOff when busy
#6102 02/27/04 08:23 PM
Joined: Aug 1999
Posts: 22,208
Member
Offline
Member
Joined: Aug 1999
Posts: 22,208
If TOracleSession.ThreadSafe = False in a multi-threaded application, you must be careful when you access the same session from different threads. Simultaneous access can lead to unpredictable results.

If a thread is waiting for a lock, then you do not have much control. Like you said, BreakExecution does not help (the Oracle Server does not respond in case of a lock). You can only wait until the lock is released.


Marco Kalter
Allround Automations
Re: Application crash without exception on LogOff when busy
#6103 02/27/04 08:27 PM
Joined: Feb 2004
Posts: 41
R
Ralf Offline OP
Member
OP Offline
Member
R
Joined: Feb 2004
Posts: 41
It's not the same session. The thread has its own TOracleSession. And what if the execution takes on for ever?? There must be a possibility to stop the execution.

Re: Application crash without exception on LogOff when busy
#6104 02/27/04 08:29 PM
Joined: Feb 2004
Posts: 41
R
Ralf Offline OP
Member
OP Offline
Member
R
Joined: Feb 2004
Posts: 41
I just use the thread to be able to access the oraclesession. If it is hanging in main thread, the application doesn't react at all.

So one session in a thread in a delphi application and the other session is through Oracle's SQL+.

The Oracle session in the thread has ThreadSafe=false because it isn't used by more threads.

Re: Application crash without exception on LogOff when busy
#6105 02/27/04 09:19 PM
Joined: Feb 2004
Posts: 41
R
Ralf Offline OP
Member
OP Offline
Member
R
Joined: Feb 2004
Posts: 41
I wrote a testproject:

Test Project

You must set the connection-info for the database and create the table as described in the top of unit1.pas.

You can add the record from SQL+ or with the button 'Add Record' that adds a record to the testtable. Then press the execute button, which inserts the same record in the same table with another session from a thread.

Re: Application crash without exception on LogOff when busy
#6106 03/01/04 10:47 PM
Joined: Aug 1999
Posts: 22,208
Member
Offline
Member
Joined: Aug 1999
Posts: 22,208
You cannot disconnect a session in the main thread that is currently executing in a background thread. All you can do is call TOracleSession.BreakExecution, and if that doesn't help, you have no real control over the session until execution finishes.


Marco Kalter
Allround Automations
Re: Application crash without exception on LogOff when busy
#6107 03/02/04 11:31 AM
Joined: Feb 2004
Posts: 41
R
Ralf Offline OP
Member
OP Offline
Member
R
Joined: Feb 2004
Posts: 41
OK, but why does my application crash when I call logoff??? It doesn't even show an exception in Delphi!

Re: Application crash without exception on LogOff when busy
#6108 03/02/04 10:44 PM
Joined: Aug 1999
Posts: 22,208
Member
Offline
Member
Joined: Aug 1999
Posts: 22,208
This is caused by the Oracle Call Interface DLL (oci.dll). Like I said, you cannot access a session from 2 different threads if ThreadSafe is false, this will lead to unpredictable results.


Marco Kalter
Allround Automations
Re: Application crash without exception on LogOff when busy
#6109 03/05/04 06:20 PM
Joined: Feb 2004
Posts: 41
R
Ralf Offline OP
Member
OP Offline
Member
R
Joined: Feb 2004
Posts: 41
Did you try my test project????
It uses 2 different sessions!!!
Then ThreadSafe isn't relevant according to your help:

Quote: "Multi-threaded, multi-session database access. No special properties need to be set, and session management is clear."

What am I missing??

Re: Application crash without exception on LogOff when busy
#6110 03/05/04 10:42 PM
Joined: Aug 1999
Posts: 22,208
Member
Offline
Member
Joined: Aug 1999
Posts: 22,208
I didn't notice that it uses multiple sessions. What exactly should I do in your application to reproduce the problem?


Marco Kalter
Allround Automations
Re: Application crash without exception on LogOff when busy
#6111 03/08/04 12:05 PM
Joined: Feb 2004
Posts: 41
R
Ralf Offline OP
Member
OP Offline
Member
R
Joined: Feb 2004
Posts: 41
You can reproduce it the way I described above...

Quote: "You can add the record from SQL+ or with the button 'Add Record' that adds a record to the testtable. Then press the execute button, which inserts the same record in the same table with another session from a thread."

So first press the button 'Add Record' and then press the other button. Make sure the table is empty.

Re: Application crash without exception on LogOff when busy
#6112 03/08/04 11:04 PM
Joined: Aug 1999
Posts: 22,208
Member
Offline
Member
Joined: Aug 1999
Posts: 22,208
This does not immediately cause a problem. If I try to close the application I get an ORA-00001 error because the session is logged off and the transaction is committed.


Marco Kalter
Allround Automations
Re: Application crash without exception on LogOff when busy
#6113 03/09/04 03:34 PM
Joined: Feb 2004
Posts: 41
R
Ralf Offline OP
Member
OP Offline
Member
R
Joined: Feb 2004
Posts: 41
My mistake. The timer is not enabled, when running the thread. Adjusted test-project:

Test Project

Just tried it with the newest evaluation version (4.0.4) and pressing the second button makes the application hang. Using our version (3.4.4) the application exits without an exception.

Can you please look at it?

Thanks.

Re: Application crash without exception on LogOff when busy
#6114 03/11/04 11:32 AM
Joined: Feb 2004
Posts: 41
R
Ralf Offline OP
Member
OP Offline
Member
R
Joined: Feb 2004
Posts: 41
Can you please look at it?
Our database server is 'randomly' crashing, which isn't very convenient for connected clients...

Re: Application crash without exception on LogOff when busy
#6115 03/11/04 10:36 PM
Joined: Aug 1999
Posts: 22,208
Member
Offline
Member
Joined: Aug 1999
Posts: 22,208
I will check it out tomorrow.


Marco Kalter
Allround Automations
Re: Application crash without exception on LogOff when busy
#6116 03/12/04 06:32 PM
Joined: Aug 1999
Posts: 22,208
Member
Offline
Member
Joined: Aug 1999
Posts: 22,208
I ran the demo, and it does indeed hang. This is because your timer event attempts to disconnect the session that is currently executing in the background thread. Like I said, this will lead to unpredictable results if ThreadSafe = False, and to a hangup if ThreadSafe = True. The LogOff must wait until the thread is finished executing the query.


Marco Kalter
Allround Automations
Re: Application crash without exception on LogOff when busy
#6117 03/12/04 07:27 PM
Joined: Feb 2004
Posts: 41
R
Ralf Offline OP
Member
OP Offline
Member
R
Joined: Feb 2004
Posts: 41
Putting the timer in the thread makes no difference... But maybe it's not really 'in' the thread. Aside from this: how can I check whether a session (a query or whatever) is still busy?

Re: Application crash without exception on LogOff when busy
#6118 03/16/04 12:42 AM
Joined: Aug 1999
Posts: 22,208
Member
Offline
Member
Joined: Aug 1999
Posts: 22,208
The timer event will always occur in the main thread, it does not matter where you create it.

To see if a session is busy, you would need to create your own administration. You could also simply check if your thread is suspended. Only then is it safe to access the session from the main thread.


Marco Kalter
Allround Automations
Re: Application crash without exception on LogOff when busy
#6119 03/16/04 01:04 PM
Joined: Oct 1999
Posts: 138
Eschborn, Germany
Member
Offline
Member
Joined: Oct 1999
Posts: 138
Eschborn, Germany
Hi Marco,

this was the reason why i asked for such a property some time ago wink
Any chance to get it someone ?

Greetings
Jens

Re: Application crash without exception on LogOff when busy
#6120 03/16/04 11:05 PM
Joined: Aug 1999
Posts: 22,208
Member
Offline
Member
Joined: Aug 1999
Posts: 22,208
I realized that when I wrote my previous reply wink . It's still on the to-do list.


Marco Kalter
Allround Automations
Re: Application crash without exception on LogOff when busy
#6121 03/17/05 05:46 PM
Joined: Jun 2004
Posts: 12
France
Member
Offline
Member
Joined: Jun 2004
Posts: 12
France
Hi Marco,

In a reply you posted on 15 March, 2004 14:42 (Topic: Application crash without exception on LogOff when busy ) :

What did you want to say exactly by "The timer event will always occur in the main thread, it does not matter where you create it."

Does it means a TTimer.timer procedure where I execute a TOraclequery with Session1 in Thread1 can cause a hang in principal thread working itself with its own session?

Greetings
CdeV

Re: Application crash without exception on LogOff when busy
#6122 03/17/05 08:41 PM
Joined: Aug 1999
Posts: 22,208
Member
Offline
Member
Joined: Aug 1999
Posts: 22,208
A TTimer.OnTimer event is generated by Windows, and occurs within the main thread of the application (where all windows events occur). If you access a session from this event, you can interfere with other threads accessing the same session. It cannot interfere with other application functions from the main thread that access this session.


Marco Kalter
Allround Automations
Re: Application crash without exception on LogOff when busy
#6123 03/17/05 10:17 PM
Joined: Jun 2004
Posts: 12
France
Member
Offline
Member
Joined: Jun 2004
Posts: 12
France
OK. Thanks Marco.

In fact, I tried to use Timers created with each of my sessions to insure the session is always connected. :p
So, is there a possibility to periodically refresh all sessions (with or without timers). The goal is to prevent each session to be disconnected after the user's profile defined parameter "Idle time" (60 minutes in this case and cannot be changed mad ).

Re: Application crash without exception on LogOff when busy
#6124 03/18/05 07:37 PM
Joined: Aug 1999
Posts: 22,208
Member
Offline
Member
Joined: Aug 1999
Posts: 22,208
If you set TOracleSession.ThreadSafe to True for all sessions, you can still use a Timer to call TOracleSession.CheckConnection(True) for each session. This will be blocked by simultaneous access from the threads, but it will work okay.

The CheckConnection function will keep the session alive by preventing too much idle time, and will (attempt to) reconnect in case of fatal other failures, such as a killed session, a database that was shutdown and restarted, network failures, and so on.


Marco Kalter
Allround Automations
Page 1 of 3 1 2 3

Moderated by  support 

Link Copied to Clipboard
Powered by UBB.threads™ PHP Forum Software 7.7.4
(Release build 20200307)
Responsive Width:

PHP: 7.1.33 Page Time: 0.104s Queries: 13 (0.047s) Memory: 2.6265 MB (Peak: 3.0380 MB) Data Comp: Off Server Time: 2024-05-06 05:45:24 UTC
Valid HTML 5 and Valid CSS