Subject multithread app using IBO is freezing
Author GOVINDKRISHNA
I am accessing a Firebird 1.0.3 database using IBO in a multi threaded
application and my application is freezing. The applications stops responding
and Windows says application not responding.

I have been closing following this list and I think i have taken care of
everything needed to make my app thread safe.

I am putting in relevant bits of code. Could somebody please help me by
suggesting what could be the problem.

I have enclosed some stack traces of the threads along with this mail which are
showing some gds__thread_enter calls of gds32.dll.I am not so sure what exactly
this call means.But whenever my application's main thread is freezing, i have
noticed that there is more than one thread in the application executing a call
to this procedure.

Database access is done as follows in my application:-

1. I have a IB_Session object(IB_Session1) on my main form and which is the first one
in the creation order.
2. The main thread is hanging at a function which is doing a database access.
3. The function basically executes a "select procedure in the database" by creating
a new transaction.
The function is written as follows :-
function TfrmServer.SendMails:boolean;
begin
rsTobeSent:TIBOQuery;
tran:TIBOTransaction;
begin
//check if messages exist to send
rsTobeSent :=nil;
tran:=nil;
Result:=False;
try
//IB_Session1 is kept on the main form at design time.
tran:=TIBOTransaction.Create(IB_Session1);
tran.ReadOnly :=True;
tran.IB_Connection :=DBCon;
TRAN.IB_Session :=IB_Session1;
rsTobeSent :=TIBOQuery.Create(IB_Session1);
With rsTobeSent do
begin
IB_Connection :=DBCon;
IB_Transaction :=Tran;
SQL.Add('Select HasMsgs from P_HASMSGSTOSEND');
Open;
Result :=(Fieldbyname('HasMsgs').asinteger=1);
end;
tran.RollBack;
finally
FreeAndNil(rsTobeSent);
FreeAndNil(tran);
end;
end;

Main thread always is freezing while trying to open the recordset in the above function.
I dont have any other code doing database access in the main thread.

4. I have different threads created in the main thread and datamodules are created in each
of these threads with owner as nil in the Execute() function of the thread.

Code sample:-
FDMDownload :=TDMDownload.Create(nil);//FDMDownload is declared as a private
//variable in the thread

And in the datamodule I have a IB_session object(made first in the creation order),
a IB_Connection object that is created in the Constructor and IB_Session's Default connection
property set to the connection object at runtime and a IBOtransaction object created in the Datamodule with owner as Datamodule.
I have differnt dataacess methods in the datamodule that are creating IBOQuery objects
and setting the IB_connection and IB_transaction properties.

5. And also i see in the interbase.log file some entries like :-

MAILSERVER (Server) Tue Mar 23 20:18:23 2004
INET/inet_error: select in packet_receive errno = 10038

MAILSERVER (Server) Wed Mar 24 08:19:07 2004
INET/inet_error: read errno = 10054

MAILSERVER (Server) Wed Mar 24 08:19:07 2004
INET/inet_error: read errno = 10054

MAILSERVER (Server) Wed Mar 24 08:19:10 2004
INET/inet_error: read errno = 10054



Below are some five stack traces of the application.
=============================================================================
First case
=============================================================================
=============================================================================
Main Thread
=============================================================================
77f837b2 ntdll.dll NtWaitForMultipleObjects
77e87ab5 kernel32.dll WaitForMultipleObjectsEx
77e8a318 kernel32.dll WaitForMultipleObjects
40547316 gds32.dll gds__thread_enter
40545dcc gds32.dll isc_start_multiple
004046fc PlasmaServer.exe System @TryFinallyExit
00402351 PlasmaServer.exe System SysGetMem
0050d571 PlasmaServer.exe IB_Components 1526 TIB_Transaction.API_Start
0050bea6 PlasmaServer.exe IB_Components 594 TIB_Transaction.SysStart
00511b2c PlasmaServer.exe IB_Components 1372 TIB_Statement.CheckTransaction
00512dec PlasmaServer.exe IB_Components 1890 TIB_Statement.SysExecute
0051b030 PlasmaServer.exe IB_Components 2017 TIB_Dataset.SysExecute
0051a825 PlasmaServer.exe IB_Components 1817 TIB_Dataset.SysOpen
00627dcc PlasmaServer.exe IBODataset 5590 TIBODataset.DoBeforeOpen
=============================================================================
Thread 1
=============================================================================
77f837b2 ntdll.dll NtWaitForMultipleObjects
77e87ab5 kernel32.dll WaitForMultipleObjectsEx
77e8a318 kernel32.dll WaitForMultipleObjects
40547316 gds32.dll gds__thread_enter
40544300 gds32.dll isc_dsql_prepare_m
40544122 gds32.dll isc_dsql_prepare
77e14c16 user32.dll CharUpperBuffA
004046fc PlasmaServer.exe System @TryFinallyExit
004023a6 PlasmaServer.exe System SysGetMem
004046fc PlasmaServer.exe System @TryFinallyExit
00402351 PlasmaServer.exe System SysGetMem
00402829 PlasmaServer.exe System @GetMem
00404d70 PlasmaServer.exe System @NewAnsiString
00514189 PlasmaServer.exe IB_Components 2430 TIB_Statement.API_Prepare
004046fc PlasmaServer.exe System @TryFinallyExit
004023a6 PlasmaServer.exe System SysGetMem
0062ac98 PlasmaServer.exe IBODataset 7103 TIBOInternalDataset.SysSQLChange
005153cf PlasmaServer.exe IB_Components 2964 TIB_Statement.OnSQLChange
00442829 PlasmaServer.exe Classes TStringList.Changed
00500f44 PlasmaServer.exe IB_Components 491 TIB_StringList.Changed
00512dff PlasmaServer.exe IB_Components 1892 TIB_Statement.SysExecute
0051b030 PlasmaServer.exe IB_Components 2017 TIB_Dataset.SysExecute
0051a825 PlasmaServer.exe IB_Components 1817 TIB_Dataset.SysOpen
00627dcc PlasmaServer.exe IBODataset 5590 TIBODataset.DoBeforeOpen
0061847a PlasmaServer.exe DB TDataSet.SetActive
006182e0 PlasmaServer.exe DB TDataSet.Open
==========================================================================================
Thread 2
==========================================================================================
77f837b2 ntdll.dll NtWaitForMultipleObjects
77e87ab5 kernel32.dll WaitForMultipleObjectsEx
77e8a318 kernel32.dll WaitForMultipleObjects
40547316 gds32.dll gds__thread_enter
40545dcc gds32.dll isc_start_multiple
004046fc PlasmaServer.exe System @TryFinallyExit
004023a6 PlasmaServer.exe System SysGetMem
004028a3 PlasmaServer.exe System @ReallocMem
0044042f PlasmaServer.exe Classes TList.SetCapacity
00440267 PlasmaServer.exe Classes TList.Grow
00440092 PlasmaServer.exe Classes TList.Add
00502b3a PlasmaServer.exe IB_Components 198 TIB_Component.SetSession
00440092 PlasmaServer.exe Classes TList.Add
00502cb1 PlasmaServer.exe IB_Components 266 TIB_Transaction.SetSession
0050297c PlasmaServer.exe IB_Components 124 TIB_Component.CheckSession
0050d571 PlasmaServer.exe IB_Components 1526 TIB_Transaction.API_Start
0050bea6 PlasmaServer.exe IB_Components 594 TIB_Transaction.SysStart
0050cd5a PlasmaServer.exe IB_Components 1119 TIB_Transaction.SetStarted
0050b52d PlasmaServer.exe IB_Components 188 TIB_Transaction.ExecuteImmediate

==========================================================================================
Second Case
==========================================================================================
main thread ($460):
==========================================================================================
77f83786 ntdll.dll NtWaitForSingleObject
7503b869 WS2_32.DLL send
75031da6 WS2_32.DLL select
40545ed6 gds32.dll isc_start_multiple
004046fc PlasmaServer.exe System @TryFinallyExit
00402351 PlasmaServer.exe System SysGetMem
0050d571 PlasmaServer.exe IB_Components 1526 TIB_Transaction.API_Start
0050bea6 PlasmaServer.exe IB_Components 594 TIB_Transaction.SysStart
00511b2c PlasmaServer.exe IB_Components 1372 TIB_Statement.CheckTransaction
00512dec PlasmaServer.exe IB_Components 1890 TIB_Statement.SysExecute
0051b030 PlasmaServer.exe IB_Components 2017 TIB_Dataset.SysExecute
0051a825 PlasmaServer.exe IB_Components 1817 TIB_Dataset.SysOpen
00627dcc PlasmaServer.exe IBODataset 5590 TIBODataset.DoBeforeOpen
==========================================================================================
Thread 1
==========================================================================================
77f83786 ntdll.dll NtWaitForSingleObject
7503b869 WS2_32.DLL send
75031da6 WS2_32.DLL select
405427e5 gds32.dll isc_dsql_allocate_statement
00440092 PlasmaServer.exe Classes TList.Add
0050a143 PlasmaServer.exe IB_Components 2050 TIB_Connection.AllocateStmtHandle
00511bc3 PlasmaServer.exe IB_Components 1383 TIB_Statement.SysAllocate
00511d33 PlasmaServer.exe IB_Components 1441 TIB_Statement.SysPrepare
0051ba61 PlasmaServer.exe IB_Components 2279 TIB_Dataset.SysPrepare
00510f2c PlasmaServer.exe IB_Components 1037 TIB_Statement.Prepare
00626231 PlasmaServer.exe IBODataset 4734 TIBODataset.Prepare
00762a22 PlasmaServer.exe DownloadDM 598 TDMDownload.GetNewHeaders
==========================================================================================
Third Case
==========================================================================================
main thread ($34c):
77f837b2 ntdll.dll NtWaitForMultipleObjects
77e87ab5 kernel32.dll WaitForMultipleObjectsEx
77e8a318 kernel32.dll WaitForMultipleObjects
40547316 gds32.dll gds__thread_enter
40545dcc gds32.dll isc_start_multiple
0050d571 PlasmaServer.exe IB_Components 1526 TIB_Transaction.API_Start
0050bea6 PlasmaServer.exe IB_Components 594 TIB_Transaction.SysStart
00511b2c PlasmaServer.exe IB_Components 1372 TIB_Statement.CheckTransaction
00512dec PlasmaServer.exe IB_Components 1890 TIB_Statement.SysExecute
0051b030 PlasmaServer.exe IB_Components 2017 TIB_Dataset.SysExecute
0051a825 PlasmaServer.exe IB_Components 1817 TIB_Dataset.SysOpen
00627dcc PlasmaServer.exe IBODataset 5590 TIBODataset.DoBeforeOpen
==========================================================================================
thread 1
==========================================================================================
77f837b2 ntdll.dll NtWaitForMultipleObjects
77e87ab5 kernel32.dll WaitForMultipleObjectsEx
77e8a318 kernel32.dll WaitForMultipleObjects
40547316 gds32.dll gds__thread_enter
40543d3d gds32.dll isc_dsql_free_statement
00512d3e PlasmaServer.exe IB_Components 1867 TIB_Statement.SysUnprepare
00511c54 PlasmaServer.exe IB_Components 1404 TIB_Statement.SysDeallocate
00510f84 PlasmaServer.exe IB_Components 1049 TIB_Statement.Unprepare
00626256 PlasmaServer.exe IBODataset 4738 TIBODataset.Unprepare
006254b3 PlasmaServer.exe IBODataset 4043 TIBODataset.Destroy
==========================================================================================
Thread2
==========================================================================================
77f837b2 ntdll.dll NtWaitForMultipleObjects
77e87ab5 kernel32.dll WaitForMultipleObjectsEx
77e8a318 kernel32.dll WaitForMultipleObjects
40547316 gds32.dll gds__thread_enter
40540d5d gds32.dll isc_attach_database
0050984d PlasmaServer.exe IB_Components 1843 TIB_Connection.API_Connect
00507dcb PlasmaServer.exe IB_Components 1159 TIB_Connection.SysConnect
00505775 PlasmaServer.exe IB_Components 295 TIB_Connection.Connect
00505804 PlasmaServer.exe IB_Components 329 TIB_Connection.Open
007634bf PlasmaServer.exe DownloadDM 797 TDMDownload.Create
==========================================================================================
Fourth Case
==========================================================================================
main thread ($554):
77f837b2 ntdll.dll NtWaitForMultipleObjects
77e87ab5 kernel32.dll WaitForMultipleObjectsEx
77e8a318 kernel32.dll WaitForMultipleObjects
40547316 gds32.dll gds__thread_enter
40545dcc gds32.dll isc_start_multiple
004046fc PlasmaServer.exe System @TryFinallyExit
00402351 PlasmaServer.exe System SysGetMem
0050d571 PlasmaServer.exe IB_Components 1526 TIB_Transaction.API_Start
0050bea6 PlasmaServer.exe IB_Components 594 TIB_Transaction.SysStart
00511b2c PlasmaServer.exe IB_Components 1372 TIB_Statement.CheckTransaction
00512dec PlasmaServer.exe IB_Components 1890 TIB_Statement.SysExecute
0051b030 PlasmaServer.exe IB_Components 2017 TIB_Dataset.SysExecute
0051a825 PlasmaServer.exe IB_Components 1817 TIB_Dataset.SysOpen
00627dcc PlasmaServer.exe IBODataset 5590 TIBODataset.DoBeforeOpen
0061847a PlasmaServer.exe DB TDataSet.SetActive
006182e0 PlasmaServer.exe DB TDataSet.Open
==========================================================================================
Thread 1
==========================================================================================
77f837b2 ntdll.dll NtWaitForMultipleObjects
77e87ab5 kernel32.dll WaitForMultipleObjectsEx
77e8a318 kernel32.dll WaitForMultipleObjects
40547316 gds32.dll gds__thread_enter
40543d3d gds32.dll isc_dsql_free_statement
00512d3e PlasmaServer.exe IB_Components 1867 TIB_Statement.SysUnprepare
00511c54 PlasmaServer.exe IB_Components 1404 TIB_Statement.SysDeallocate
00510f84 PlasmaServer.exe IB_Components 1049 TIB_Statement.Unprepare
00626256 PlasmaServer.exe IBODataset 4738 TIBODataset.Unprepare
006254b3 PlasmaServer.exe IBODataset 4043 TIBODataset.Destroy
==========================================================================================
Fifth Case
==========================================================================================
main thread ($5e0):
77f837b2 ntdll.dll NtWaitForMultipleObjects
77e87ab5 kernel32.dll WaitForMultipleObjectsEx
77e8a318 kernel32.dll WaitForMultipleObjects
40547316 gds32.dll gds__thread_enter
40545dcc gds32.dll isc_start_multiple
004046fc PlasmaServer.exe System @TryFinallyExit
00402351 PlasmaServer.exe System SysGetMem
0050d571 PlasmaServer.exe IB_Components 1526 TIB_Transaction.API_Start
0050bea6 PlasmaServer.exe IB_Components 594 TIB_Transaction.SysStart
00511b2c PlasmaServer.exe IB_Components 1372 TIB_Statement.CheckTransaction
00512dec PlasmaServer.exe IB_Components 1890 TIB_Statement.SysExecute
0051b030 PlasmaServer.exe IB_Components 2017 TIB_Dataset.SysExecute
0051a825 PlasmaServer.exe IB_Components 1817 TIB_Dataset.SysOpen
00627dcc PlasmaServer.exe IBODataset 5590 TIBODataset.DoBeforeOpen
==========================================================================================
Thread 1
==========================================================================================
77f837b2 ntdll.dll NtWaitForMultipleObjects
77e87ab5 kernel32.dll WaitForMultipleObjectsEx
77e8a318 kernel32.dll WaitForMultipleObjects
40547316 gds32.dll gds__thread_enter
4054530a gds32.dll isc_rollback_transaction
00521a12 PlasmaServer.exe IB_Components 5144 TIB_Dataset.GetBufferRowCount
00517be6 PlasmaServer.exe IB_Components 371 TIB_Dataset.BufferActive
0051a643 PlasmaServer.exe IB_Components 1713 TIB_Dataset.Close
0050c142 PlasmaServer.exe IB_Components 712 TIB_Transaction.SysProcessCommitAction
0050d905 PlasmaServer.exe IB_Components 1650 TIB_Transaction.API_Rollback
0050c9df PlasmaServer.exe IB_Components 992 TIB_Transaction.SysRollbackBegin
0050c909 PlasmaServer.exe IB_Components 964 TIB_Transaction.SysRollback
0050b89c PlasmaServer.exe IB_Components 289 TIB_Transaction.Rollback
==========================================================================================
Thread 2
==========================================================================================

77f837b2 ntdll.dll NtWaitForMultipleObjects
77e87ab5 kernel32.dll WaitForMultipleObjectsEx
77e8a318 kernel32.dll WaitForMultipleObjects
40547316 gds32.dll gds__thread_enter
40540f4c gds32.dll isc_attach_database
0050984d PlasmaServer.exe IB_Components 1843 TIB_Connection.API_Connect
00507dcb PlasmaServer.exe IB_Components 1159 TIB_Connection.SysConnect
00505775 PlasmaServer.exe IB_Components 295 TIB_Connection.Connect
00505804 PlasmaServer.exe IB_Components 329 TIB_Connection.Open
007634bf PlasmaServer.exe DownloadDM 797 TDMDownload.Create



Regards

S. Govindkrishna
JL Infomatrix Limited



>>> This mail is created in Hamsa (www.jlmatrix.com) <<<