Page 1 of 1

Cannot quit app cleanly after first use of unidac - updated

Posted: Wed 20 May 2015 15:15
by michaschumann
I have a strange Delphi problem in a quite huge application I migrated from FIB to Unidac:

As soon as the connection to firebird is used once , I cannto quit the application by application.terminate anymore. Symptom is: My application seems to get into an infinitive loop and then crashes with an access violation. Currently I used a workaround by terminating "the hard way", but this does not allow using fastMM features for debugging memory leaks.

I traced down the problem to appear in system.pas:finalizeUnits. It is kind of strange that finalizeUnits calls itself in the except path:

Code: Select all

procedure FinalizeUnits;
...
try
    while Count > 0 do
    begin
      Dec(Count);
      InitContext.InitCount := Count;
      P := Table^[Count].FInit;
      if Assigned(P) and Assigned(Pointer(P^)) then
      begin
{$IF defined(MSWINDOWS)}
        TProc(P)();
{$ELSEIF (defined(POSIX) and defined(CPUX86))}
        CallProc(P, InitContext.Module^.GOT);
{$ELSE}
        TProc(P)();
{$ENDIF}
      end;
    end;
  except
    FinalizeUnits;  { try to finalize the others }
    raise;
  end;
...
I also traced it down to only appear if a connection to FIrebird was made with unidac. If I quit the application right before db.connected:=true; (db is a TUniConnection), it works fine, immediately after this command quitting without the exception is no longer possible. I tried to disconnect again and changing several options of unidac to no avail.

Even if I use a seperate TUniConnection DBTest in the datamodule without any events used and no data components connected to it, this error is reproducable:

Code: Select all

  // if I quit here, everything is fine
  dbtest.SpecificOptions.values['ClientLibrary'] := Progdir + 'fbclient\fbclient.dll';
  dbtest.username := su;
  dbtest.password := sp;
  dbtest.Database := getDBFileName(sDB);
  dbtest.Server := getDBServerName(sDB);
  dbtest.connected := true;
  // If I quit here, the access violation occurs
  
I suspect that unloading firebird.dll is the problem.

Update: Following a suggestion from the Stackoverflow forum I traced the count index in system.pas to find the unit which is causing the problem by stepping into. Unfortunately the finalization routine causing the problem points into nirvana and not into any unit.

Environment: Delphi XE6 Enterprise, Firebird 2.5.4 embedded client connecting to Firebird 1.56 oder 2.54.

Any help would be very appreciated as I urgently have to track down a memory leak and cannot use fastMM wit this error;-(

Best regards Michael

Re: Cannot quit app cleanly after first use of unidac - updated

Posted: Wed 20 May 2015 17:55
by michaschumann
I created a small test program to reproduce the problem. It uses Firebird 2.5.4 embedded server in subdirectory fbclient. The app connects to a database in oncreate and on quit it crashes. I buildt the same thing with firedac, this quits without any problems.

Even more stange is that the effect only seems to happen if the application is run within the ide. This I discovered while peparing the sample app for analysis by anyone who wants to help.

Feel free to download the zip with source and all required files at http://dl.itc-ms.de/test.zip (8MB).

Any help is still very appreciated!

Michael

Re: Cannot quit app cleanly after first use of unidac - updated

Posted: Thu 21 May 2015 12:39
by ViktorV
You are right. This AV occurs in fbembed.dll on attempt to unload it, if there was an attempt to connect to localhost before this. We will try to avoid this behavior in one of the next UniDAC builds.
As a workaround, you can try to set the TUniConnection.Server property to an empty string:

Code: Select all

UniConnection.Server := ''; 

Re: Cannot quit app cleanly after first use of unidac - updated

Posted: Tue 26 May 2015 15:30
by michaschumann
Thanks for your answer. Unfortunately this also happens when connecting to a remote server in the network.

Re: Cannot quit app cleanly after first use of unidac - updated

Posted: Wed 27 May 2015 09:50
by ViktorV
Yes, such an error will occur on an attempt of fbembed.dll to connect to any remote server via network protocol (network protocol is used for localhost as well). Since fbembed.dll is designed for work with a local database only (UniConnection.Server = '').
It is not a bug of UniDAC, but a specificity of Firebird Embedded functionality.
We have avoided this disadvantage of fbembed.dll, the fix will be included in the next UniDAC build.

Re: Cannot quit app cleanly after first use of unidac - updated

Posted: Wed 27 May 2015 11:39
by michaschumann
Great. I could then alos avoid it by using fbclient for any remote connection? I will try this and look forward to the next UNIDAC version.

Thanks for your support.

Michael

Re: Cannot quit app cleanly after first use of unidac - updated

Posted: Wed 27 May 2015 12:58
by ViktorV
The fbembed.dll library is a part of Firebird Embedded server, that is designed for work with local databases. When connecting to a remote server with the help of this library, errors can occur. fbclient.dll is the Firebird client library designed for work with remote server via network protocol, so you can use it in the current version of UniDAC for connection to a remote server.

Re: Cannot quit app cleanly after first use of unidac - updated

Posted: Fri 29 May 2015 11:01
by michaschumann
I now will deploy both the embedded server and the "real" fbclient with my software and switch to the embedded server if the server property is empty. This works well and I can always quit (also in the IDE) without problems.

Since I had a lot of not reproducable connection errors to firebird servers, also avs (alway on DB access but always on different positions and without any systematics) in some installations of my software, do you think this might be caused by fbembed? I will see when the next release. Hopefully using fbembed with remote database is the root of all this evil ;-)

Michael

Re: Cannot quit app cleanly after first use of unidac - updated

Posted: Fri 29 May 2015 12:32
by ViktorV
Yes, the error can occur due to using fbembed.dll for work with a remote server.
It is good to see that the issue has been resolved.
Feel free to contact us if you have any further questions about IBDAC.

Re: Cannot quit app cleanly after first use of unidac - updated

Posted: Sat 30 May 2015 09:35
by michaschumann
Thank you very much for your support, I am glad having chosen UNIDAC!

Re: Cannot quit app cleanly after first use of unidac - updated

Posted: Wed 03 Jun 2015 08:12
by ViktorV
If you have any questions during using our products, please don't hesitate to contact us - and we will try to help you solve them.

Re: Cannot quit app cleanly after first use of unidac - updated

Posted: Fri 19 Jun 2015 02:52
by FredS
michaschumann wrote: Hopefully using fbembed with remote database is the root of all this evil ;-)
Michael
When I used an embedded DLL not VERSION specific for a remote server I ran into trouble.
This became very apparent when I moved to 2.5.4 for embedded yet still had a Linux Fb server at v 2.5

After reading this thread I have rename the embedded DLLs to fbembed254.dll, this has solved the issue with test running FB3 which always complained about not being able to run Engine12 when an fbclient.dll was already loaded.

One NOTE: Renaming the Fb3 DLL caused my app to hang and not close properly, setting that back to default fixed the issue.

Re: Cannot quit app cleanly after first use of unidac - updated

Posted: Fri 19 Jun 2015 05:45
by michaschumann
Thanks for that information.

I soon will know whether using the "real" client against the DB instead of the embedded server solves the sporadic connection problems in some instances of my application. I will post my experiences here.

Michael