Recent

Author Topic: [SOLVED] [IBX] Error, Project raised exception class 'External : SIGSEGV'  (Read 5694 times)

incendio

  • Full Member
  • ***
  • Posts: 126
Hi guys,

I tried IBX on Lazarus 2.0.6 on Linux Mint 20, got an error when running an app.

This error caused by Firebird server restarted when app still running.

When Firebird server restarted, tried to close TIBDatabase and open again, this is when the error throw.

This is not happen on Windows OS.

Here are the codes
Code: Pascal  [Select][+][-]
  1. unit main;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, IBDatabase;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Button1: TButton;
  16.     Dba: TIBDatabase;
  17.     Trs: TIBTransaction;
  18.     procedure Button1Click(Sender: TObject);
  19.     procedure FormCreate(Sender: TObject);
  20.     procedure OpenDt();
  21.   private
  22.  
  23.   public
  24.  
  25.   end;
  26.  
  27. var
  28.   Form1: TForm1;
  29.  
  30. implementation
  31.  
  32. {$R *.lfm}
  33.  
  34. { TForm1 }
  35. procedure TForm1.OpenDt();
  36. begin
  37.   Dba.Close; // this line caused an error after Firebird Server restarted
  38.   Dba.Open;
  39.   Trs.Active:= true;
  40.   ShowMessage('Dba Opened.');
  41. end;
  42.  
  43. procedure TForm1.FormCreate(Sender: TObject);
  44. begin
  45.   OpenDt();
  46. end;
  47.  
  48. procedure TForm1.Button1Click(Sender: TObject);
  49. begin
  50.   OpenDt(); // Clicked after Firebird Server restarted
  51. end;
  52.  
  53. end.
  54.  

Anyone know how to fix this?
« Last Edit: December 04, 2021, 03:54:42 am by incendio »

tonyw

  • Full Member
  • ***
  • Posts: 242
    • MWA Software
Re: [IBX] Error, Project raised exception class 'External : SIGSEGV'
« Reply #1 on: December 01, 2021, 01:08:12 pm »
You need to call Dba.ForceClose rather than Close. Close will just keep returning an exception.

incendio

  • Full Member
  • ***
  • Posts: 126
Re: [IBX] Error, Project raised exception class 'External : SIGSEGV'
« Reply #2 on: December 01, 2021, 02:39:02 pm »
I have tried ForceClose & Reconnect, nothing worked.

Same codes that runs OK in windows,  throws error in Linux.

Something strange though, on a connection that only has TIBSQL tied to it, a call to Close did not raise an error.

Only connection that have TIBDataset tied to it, raised an error.

tonyw

  • Full Member
  • ***
  • Posts: 242
    • MWA Software
Re: [IBX] Error, Project raised exception class 'External : SIGSEGV'
« Reply #3 on: December 01, 2021, 02:44:51 pm »
When you try to close a database, IBX will attempt to commit/rollback any open transactions. That will be where you are mostly likely to be getting an error. I have tried to duplicate your problem, but all I see is a Firebird exception when I stop the server - Close always gives the same exception (as expected) - and ForceClose works.

Somewhere there may be an unprotected call to a low level handle. If you could post the stack tree when you get a sigserv then this might help.

incendio

  • Full Member
  • ***
  • Posts: 126
Re: [IBX] Error, Project raised exception class 'External : SIGSEGV'
« Reply #4 on: December 02, 2021, 07:58:04 am »
When you try to close a database, IBX will attempt to commit/rollback any open transactions. That will be where you are mostly likely to be getting an error. I have tried to duplicate your problem, but all I see is a Firebird exception when I stop the server - Close always gives the same exception (as expected) - and ForceClose works.

Somewhere there may be an unprotected call to a low level handle. If you could post the stack tree when you get a sigserv then this might help.
Sorry, new to Lazarus here. What is stack tree and how to get it?

I use the exact codes from this post :
https://forum.lazarus.freepascal.org/index.php/topic,57344.0.html

tonyw

  • Full Member
  • ***
  • Posts: 242
    • MWA Software
Re: [IBX] Error, Project raised exception class 'External : SIGSEGV'
« Reply #5 on: December 02, 2021, 10:32:52 am »
When you try to close a database, IBX will attempt to commit/rollback any open transactions. That will be where you are mostly likely to be getting an error. I have tried to duplicate your problem, but all I see is a Firebird exception when I stop the server - Close always gives the same exception (as expected) - and ForceClose works.

Somewhere there may be an unprotected call to a low level handle. If you could post the stack tree when you get a sigserv then this might help.
Sorry, new to Lazarus here. What is stack tree and how to get it?

I use the exact codes from this post :
https://forum.lazarus.freepascal.org/index.php/topic,57344.0.html
Sorry meant the "Call Stack". You find this on the View->Debug Windows menu. When an exception occurs, it shows you not just where the exception was raised but the call history so that you can determine how the problem came above. Example attached.

incendio

  • Full Member
  • ***
  • Posts: 126
Re: [IBX] Error, Project raised exception class 'External : SIGSEGV'
« Reply #6 on: December 03, 2021, 02:27:54 am »
Here is the content of Call Stack :

#0 RELEASE(0x7ffff54daae8) at fbintf/client/3.0/firebird/Firebird.pas:3684
#1 FREEHANDLE(0x7ffff5aee480) at fbintf/client/3.0/FB30Transaction.pas:104
#2 ROLLBACK(0x7ffff5aee480, true) at fbintf/client/3.0/FB30Transaction.pas:200
#3 ENDTRANSACTION(0x7ffff622f720, TAROLLBACK, true) at runtime/nongui/IBDatabase.pas:1771
#4 BEFOREDATABASEDISCONNECT(0x7ffff622f720, 0x7ffff5a0a040) at runtime/nongui/IBDatabase.pas:1914
#5 INTERNALBEFORECLOSE(0x7ffff5a0a040) at runtime/nongui/IBDatabase.pas:733
#6 INTERNALCLOSE(0x7ffff5a0a040) at runtime/nongui/IBDatabase.pas:703
#7 DODISCONNECT(0x7ffff5a0a040) at runtime/nongui/IBDatabase.pas:531
#8 DB$_$TCUSTOMCONNECTION_$__$$_SETCONNECTED$BOOLEAN at :0
#9 ?? at :0
#10 ?? at :0


tonyw

  • Full Member
  • ***
  • Posts: 242
    • MWA Software
Re: [IBX] Error, Project raised exception class 'External : SIGSEGV'
« Reply #7 on: December 03, 2021, 10:23:06 am »
Thanks for the above call stack. It's easy enough to see where the problem arises. On the face of it, this is a classic "double free" - of the transaction handle. The exception occurs in libfbclient.so.2 when IBX calls "release" to free the handle. If does so after a forced Rollback (see 2nd parameter on line 2).

Looking at the code, the handle is always protected and I would guess that the problem is that Firebird automatically freed the handle when the connection was lost. The simplest way of avoiding a problem is probably to ignore the exception by modifying the FreeHandle procedure to:

Code: Pascal  [Select][+][-]
  1. procedure TFB30Transaction.FreeHandle;
  2. begin
  3.   if assigned(FTransactionIntf) then
  4.   try
  5.     FTransactionIntf.release;
  6.   except {ignore}
  7.   end;
  8.   FTransactionIntf := nil;
  9. end;

This should be safe given that the exception occurs when you are trying to get rid of the handle anyway and on recovery from an exceptional condition. A final version of the fix will probably only ignore the exception when "Force" is true - but that requires more changes to the unit.

incendio

  • Full Member
  • ***
  • Posts: 126
Re: [IBX] Error, Project raised exception class 'External : SIGSEGV'
« Reply #8 on: December 04, 2021, 03:52:56 am »
Thanks, that solved the problem.

 

TinyPortal © 2005-2018