Error reading data from the connection

Discussion of open issues, suggestions and bugs regarding IBDAC (InterBase Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
zd
Posts: 78
Joined: Sun 01 Jul 2007 13:16

Error reading data from the connection

Post by zd » Mon 06 Sep 2010 09:23

Hi!

I've upgraded to IBDAC 3.10.0.16 from 2.5 and I've ran into a problem.

At a point where my program used to work perfectly, sometimes an "Error reading data from the connection" EIBCError is displayed.

The problem is that the error can't always be reproduced, but tests show it happens at the same place.

I've an idea on what is causing it, and I need your feedback to work something out.

The following is happening at the place of the error:

1. An INSERT INTO command is executed using IBCQuery.ExecSQL.

--- Meanwhile ---

In the database an After Insert trigger is fired, which inserts a record to a log table and fires a Firebird event.

--- Back to the program

2. After ExecSQL a RET_ paremeters are stored which were returned by the INSERT INTO - RETURNING ... query.

3. Using INSERT INTO another record is inserted to a separate table. IBCQuery.ExecSQL is called.

-----> And this is where the "Error reading data from the connection" error is raised, straight after the second ExecSQL.

Please note that in order to handle the event generated by the AFTER INSERT trigger, an IBCAlerter is used. Once the alerter receives the event, it does a query on the log table using a separate, IBCQuery2 component (IBCQuery and IBCQuery2 are using the same IBCConnection component).

Since the error happens at the same place and not always but just from time-to-time, I believe this must be an issue with the IBCAlerter component. (which is known to be a very problematic component by IBDAC customers :-))

Do you guys have any ideas on what might be causing the problem?

Did you change anything in how IBCAlerter works in the past few versions of IBDAC? Are alerts still executed in the main thread and what you do there is considered "thread safe"?

Here are some Eurekalog error logs:
---------------------------------------------------------------------------------------------------------
|Address |Module |Unit |Class |Procedure/Method |Line |
---------------------------------------------------------------------------------------------------------
|Running Thread: ID=1496; Priority=0; Class=; [Main] |
|-------------------------------------------------------------------------------------------------------|
|7C903247|ntdll.dll | | |RtlConvertUlongToLargeInteger| |
|78144FB0|MSVCR80.dll | | |memcpy | |
|7C90E485|ntdll.dll | | |KiUserApcDispatcher | |

I've taken out some lines here, it just shows where the error happens in my code...

|7E36BFFB|user32.dll | | |NotifyWinEvent | |
|7C90ECBA|ntdll.dll | | |RtlMultiByteToUnicodeN | |
|7C90EB94|ntdll.dll | | |RtlAnsiStringToUnicodeString | |
|7C90D328|ntdll.dll | | |ZwFindAtom | |
|7E36BD41|user32.dll | | |PtInRect | |
|7E36B8FE|user32.dll | | |SendMessageW | |
|7E36F658|user32.dll | | |CallWindowProcA | |
|7E36F642|user32.dll | | |CallWindowProcA | |
|7C802540|kernel32.dll| | |WaitForSingleObjectEx | |
|7C80252D|kernel32.dll| | |WaitForSingleObject | |
|7C90DA28|ntdll.dll | | |NtReleaseMutant | |
|7C8024B1|kernel32.dll| | |ReleaseMutex | |
|7E37E0C9|user32.dll | | |PostThreadMessageW | |
|7C9010E0|ntdll.dll | | |RtlLeaveCriticalSection | |
|7E3694DA|user32.dll | | |GetCapture | |
|7E36F891|user32.dll | | |CallNextHookEx | |
|7E3696C2|user32.dll | | |DispatchMessageA | |
|7E3696B8|user32.dll | | |DispatchMessageA | |
|-------------------------------------------------------------------------------------------------------|
| |
|Running Thread: ID=1748; Priority=0; Class=TWorkerThread |
|-------------------------------------------------------------------------------------------------------|
|7E37F3C7|user32.dll | | |SendMessageA | |
|7E37F383|user32.dll | | |SendMessageA | |
|0053C9AA|Program.exe|VirtualTrees.pas|TWorkerThread |ChangeTreeStates |5194[2] |
|0053C970|Program.exe|VirtualTrees.pas|TWorkerThread |ChangeTreeStates |5192[0] |
|0053CACD|Program.exe|VirtualTrees.pas|TWorkerThread |Execute |5244[37] |
|-------------------------------------------------------------------------------------------------------|
|Calling Thread: ID=1496; Priority=0; Class=; [Main] |
|-------------------------------------------------------------------------------------------------------|
|0053C927|Program.exe|VirtualTrees.pas|TWorkerThread |Create |5174[2] |
|0053C8F4|Program.exe|VirtualTrees.pas|TWorkerThread |Create |5172[0] |
|0053C885|Program.exe|VirtualTrees.pas| |AddThreadReference |5125[9] |
|0053C850|Program.exe|VirtualTrees.pas| |AddThreadReference |5116[0] |
|0054625E|Program.exe|VirtualTrees.pas|TBaseVirtualTree |Create |11644[87]|
|00545F94|Program.exe|VirtualTrees.pas|TBaseVirtualTree |Create |11557[0] |
|0055FA15|Program.exe|VirtualTrees.pas|TCustomVirtualStringTree|Create |29621[1] |
|-------------------------------------------------------------------------------------------------------|
| |
|Running Thread: ID=2304; Priority=0; Class=TGDSAlerterThread |
|-------------------------------------------------------------------------------------------------------|
|7C90DF58|ntdll.dll | | |ZwWaitForSingleObject | |
|7C802540|kernel32.dll| | |WaitForSingleObjectEx | |
|7C80252D|kernel32.dll| | |WaitForSingleObject | |
|7C802520|kernel32.dll| | |WaitForSingleObject | |
|02DBBA5D|fbclient.dll| | |gds__alloc | |
|-------------------------------------------------------------------------------------------------------|
|Calling Thread: ID=1496; Priority=0; Class=; [Main] |
|-------------------------------------------------------------------------------------------------------|
|7C9010E0|ntdll.dll | | |RtlLeaveCriticalSection | |
|7E36CEA6|user32.dll | | |MonitorFromWindow | |
|-------------------------------------------------------------------------------------------------------|
| |
|Running Thread: ID=1380; Priority=0; Class=TGDSAlerterThread |
|-------------------------------------------------------------------------------------------------------|
|7C90DF58|ntdll.dll | | |ZwWaitForSingleObject | |
|7C802540|kernel32.dll| | |WaitForSingleObjectEx | |
|7C80252D|kernel32.dll| | |WaitForSingleObject | |
|7C802520|kernel32.dll| | |WaitForSingleObject | |
|02DBBA5D|fbclient.dll| | |gds__alloc | |
|-------------------------------------------------------------------------------------------------------|
|Calling Thread: ID=1496; Priority=0; Class=; [Main] |
|-------------------------------------------------------------------------------------------------------|
|7C9010E0|ntdll.dll | | |RtlLeaveCriticalSection | |
|7E36CEA6|user32.dll | | |MonitorFromWindow | |
|-------------------------------------------------------------------------------------------------------|
| |
|Running Thread: ID=2196; Priority=0; Class=TGDSAlerterThread |
|-------------------------------------------------------------------------------------------------------|
|7C90DF58|ntdll.dll | | |ZwWaitForSingleObject | |
|7C802540|kernel32.dll| | |WaitForSingleObjectEx | |
|7C80252D|kernel32.dll| | |WaitForSingleObject | |
|7C802520|kernel32.dll| | |WaitForSingleObject | |
|02DBBA5D|fbclient.dll| | |gds__alloc | |
|-------------------------------------------------------------------------------------------------------|
|Calling Thread: ID=1496; Priority=0; Class=; [Main] |
|-------------------------------------------------------------------------------------------------------|
|7C9010E0|ntdll.dll | | |RtlLeaveCriticalSection | |
|7E36CEA6|user32.dll | | |MonitorFromWindow | |
|-------------------------------------------------------------------------------------------------------|
| |
|Running Thread: ID=1780; Priority=0; Class=TGDSAlerterThread |
|-------------------------------------------------------------------------------------------------------|
|7C90DF58|ntdll.dll | | |ZwWaitForSingleObject | |
|78144FB0|MSVCR80.dll | | |memcpy | |
|02DC55BD|fbclient.dll| | |isc_event_counts | |
|7C802540|kernel32.dll| | |WaitForSingleObjectEx | |
|7C80252D|kernel32.dll| | |WaitForSingleObject | |
|7C802520|kernel32.dll| | |WaitForSingleObject | |
|02DBBA5D|fbclient.dll| | |gds__alloc | |
|-------------------------------------------------------------------------------------------------------|
|Calling Thread: ID=1496; Priority=0; Class=; [Main] |
|-------------------------------------------------------------------------------------------------------|
|7C9010E0|ntdll.dll | | |RtlLeaveCriticalSection | |
|7E36CEA6|user32.dll | | |MonitorFromWindow | |
---------------------------------------------------------------------------------------------------------
Note: I'm using Delphi7 with FB2.1.

Thanks!

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Tue 07 Sep 2010 11:18

I can not reproduce the problem. Please try to compose a small sample to demonstrate the problem and send it to dmitryg*devart*com.

TIBCAlerter works in a separate thread that is created on alerter starting.

zd
Posts: 78
Joined: Sun 01 Jul 2007 13:16

Post by zd » Tue 07 Sep 2010 12:40

Hello!

Since my report I've done more thorough testing and the same problem appeared at another part of the program as well. Same scenario: AFTER INSERT trigger generates an event, and when the program tries to log the changes in a table ExecSQL shows a -902 "Error reading data from the connection" error.

In order to make an example, I'll need your help:
It seems that the problem only appears stastically 1 out of 10 times but sometimes I can't reproduce it even if I try 20 times. So I think it depends on the proper timing, and I have no idea how to make a sample for you!

Any ideas?

I do believe though that this problem is caused by the TIBCAlerter thread.

What's interesting is that if I execute my program from the Delphi debugger, the error is shown, but if I execute it without the debugger no error is shown but I get a deadlock.

Once during testing the deadlock also occured in the debugger. This also shows that this must be a threading issue.

Are you using Synchronize to execute the "OnEvent" event of the TIBCAlerter component?

Thanks.

zd
Posts: 78
Joined: Sun 01 Jul 2007 13:16

Post by zd » Wed 08 Sep 2010 09:59

Hello!

I've managed to make a simple sample project.

Please check your e-mail.

Thanks!

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Wed 08 Sep 2010 11:15

We have received your test project and the investigation of the problem is in progress. As soon as we solve the problem we will let you know.

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Wed 08 Sep 2010 13:45

We have reproduced this problem and fixed it. This fix will be included in the next IBDAC build.

Post Reply