* * *

Author Topic: SIGINT raises an exception in IBConnection.Close  (Read 822 times)

Sann-X!

  • New member
  • *
  • Posts: 21
SIGINT raises an exception in IBConnection.Close
« on: November 01, 2018, 01:12:25 pm »
Hi,

I have created simple project included IBConnection and Button components. Also I reassigned SigAction handler.
Code: Pascal  [Select]
  1. program project1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   {$IFDEF UNIX}{$IFDEF UseCThreads}
  7.   cthreads,
  8.   {$ENDIF}{$ENDIF}
  9.   Interfaces, // this includes the LCL widgetset
  10.   Forms, Unit1, BaseUnix;
  11.  
  12. {$R *.res}
  13.  
  14. procedure DoSig(signal: longint; info: psiginfo; context: psigcontext); cdecl;
  15. begin
  16.   if Assigned(Application) then
  17.       Application.Terminate;
  18. end;
  19.  
  20. procedure SetSigHandler(const Sig: cint; const new, old: PSigActionRec; const Handler: SigActionHandler);
  21. begin
  22.   new^.sa_handler := Handler;
  23.   fillchar(new^.Sa_Mask, SizeOf(new^.sa_mask), #0);
  24.   new^.sa_flags := 0;
  25.   {$ifdef Linux}               // Linux specific
  26.   new^.Sa_Restorer := nil;
  27.   {$endif}
  28.   fpSigAction(Sig, new, old);
  29. end;
  30.  
  31. var
  32.   new_act_term, new_act_int, new_act_hup, old_act: SigActionRec;
  33. begin
  34.   SetSigHandler(SIGTERM, @new_act_term, @old_act, @DoSig);
  35.   SetSigHandler(SIGINT, @new_act_int, @old_act, @DoSig);
  36.   SetSigHandler(SIGHUP, @new_act_hup, @old_act, @DoSig);
  37.  
  38.   {$if declared(UseHeapTrace)}
  39.   GlobalSkipIfNoLeaks := True; // supported as of debugger version 3.1.1
  40.   {$endif}
  41.  
  42.   RequireDerivedFormResource := True;
  43.   Application.Initialize;
  44.   Application.CreateForm(TForm1, Form1);
  45.   Application.Run;
  46. end.
  47.  

Success scenario:
  • Run app
  • Click button that open fb connection
  • Close app

Failed scenario:
  • Run app
  • Click button that open fb connection
  • In terminal execute command "kill -SIGINT <pid>"
Last step raises exception like as attached image. How to fix it?

DB: Firebird classic 2.5
Device: OrangePi Zero
OS: ARMBIAN 5.35 user-built Ubuntu 16.04.3 LTS 3.4.113-sun8i
« Last Edit: November 01, 2018, 01:16:39 pm by Sann-X! »

Sann-X!

  • New member
  • *
  • Posts: 21
Re: SIGTERM raises an exception in IBConnection.Close
« Reply #1 on: November 01, 2018, 01:13:08 pm »
Test project sources

sash

  • Full Member
  • ***
  • Posts: 116
Re: SIGINT raises an exception in IBConnection.Close
« Reply #2 on: November 01, 2018, 11:08:46 pm »
Why do you ever need to kill your application from outside?
If you don't like "how it is dying", use try..except.
« Last Edit: November 01, 2018, 11:11:08 pm by sash »
Lazarus 1.8.4 Unversioned directory FPC 3.0.4 x86_64-linux-gtk2

Sann-X!

  • New member
  • *
  • Posts: 21
Re: SIGINT raises an exception in IBConnection.Close
« Reply #3 on: November 02, 2018, 07:50:55 am »
Why do you ever need to kill your application from outside?
See here

If you don't like "how it is dying", use try..except.
Try..except don't help. I suppose that stack is corrupted. But why? I don't know.

DonAlfredo

  • Hero Member
  • *****
  • Posts: 994
Re: SIGINT raises an exception in IBConnection.Close
« Reply #4 on: November 02, 2018, 09:53:23 am »
I am trying to run your program on Linux Mint.
But Mint latest has FB 3.0.2.
I have patched FPC to work with this version, but your employee-file is not accepted by 3.0.2 (wrong version).
If you can help me get things running, I can try to help you with your sig-problem.

Sann-X!

  • New member
  • *
  • Posts: 21
Re: SIGINT raises an exception in IBConnection.Close
« Reply #5 on: November 02, 2018, 10:09:03 am »
But Mint latest has FB 3.0.2.
..If you can help me get things running..
I can't. My OS device supports Firebird 2.5 only.

Sann-X!

  • New member
  • *
  • Posts: 21
Re: SIGINT raises an exception in IBConnection.Close
« Reply #6 on: November 02, 2018, 12:00:50 pm »
I am trying to run your program on Linux Mint.
But Mint latest has FB 3.0.2.
You can install fb2.5 manually. See here. After this do following:
  • cp /opt/firebird/misc/firebird.init.d.debian /etc/init.d/firebird2.5
  • chmod +x /etc/init.d/firebird2.5
  • update-rc.d firebird2.5 defaults
  • sudo /etc/init.d/firebird2.5 reload

sash

  • Full Member
  • ***
  • Posts: 116
Re: SIGINT raises an exception in IBConnection.Close
« Reply #7 on: November 02, 2018, 12:34:40 pm »
I can't. My OS device supports Firebird 2.5 only.
There's virtualbox, vmware. You can install any linux there, and test if problem is specific for arm architecture or not.
Lazarus 1.8.4 Unversioned directory FPC 3.0.4 x86_64-linux-gtk2

DonAlfredo

  • Hero Member
  • *****
  • Posts: 994
Re: SIGINT raises an exception in IBConnection.Close
« Reply #8 on: November 02, 2018, 12:39:32 pm »
I would appreciate if you can design an app that does not depend on a pre-loaded database file. So, something that starts empty and creates an entry on startup or something similar.

Sann-X!

  • New member
  • *
  • Posts: 21
Re: SIGINT raises an exception in IBConnection.Close
« Reply #9 on: November 02, 2018, 01:02:42 pm »
I posted similar question on other forum (ru lang). FB developers say that fbclient set its SIG* handler in other thread. Workaround is set my own SIG* handler AFTER firebird unit/library initialization.

sash

  • Full Member
  • ***
  • Posts: 116
Re: SIGINT raises an exception in IBConnection.Close
« Reply #10 on: November 02, 2018, 01:35:51 pm »
My own test:

- Ubuntu 18.04 bionic Kernel: x86_64 Linux 4.15.0-38-generic
- FB3
- Simple default Application compiled with cthreads enabled, without any termination handlers.
 
Code: Pascal  [Select]
  1.   {$IFDEF UNIX}
  2.     cthreads,
  3.     {$ENDIF}
  4.  
- Functionality: connect to database and open select query (and stay connected) on button click.

Result:
  Is being killed  by SIGINT or SIGTERM without any messages, just as it should be.
Lazarus 1.8.4 Unversioned directory FPC 3.0.4 x86_64-linux-gtk2

Sann-X!

  • New member
  • *
  • Posts: 21
Re: SIGINT raises an exception in IBConnection.Close
« Reply #11 on: November 02, 2018, 04:01:09 pm »
My own test:

- Ubuntu 18.04 bionic Kernel: x86_64 Linux 4.15.0-38-generic
- FB3
- Simple default Application compiled with cthreads enabled, without any termination handlers.
 
Code: Pascal  [Select]
  1.   {$IFDEF UNIX}
  2.     cthreads,
  3.     {$ENDIF}
  4.  
- Functionality: connect to database and open select query (and stay connected) on button click.

Result:
  Is being killed  by SIGINT or SIGTERM without any messages, just as it should be.
If you can, please try another minimal program for test from here (first message under spoiler).

sash

  • Full Member
  • ***
  • Posts: 116
Re: SIGINT raises an exception in IBConnection.Close
« Reply #12 on: November 02, 2018, 11:41:12 pm »
If you can, please try another minimal program for test from here (first message under spoiler).

project1.lpr(130,18) Error: Illegal expression
Lazarus 1.8.4 Unversioned directory FPC 3.0.4 x86_64-linux-gtk2

Sann-X!

  • New member
  • *
  • Posts: 21
Re: SIGINT raises an exception in IBConnection.Close
« Reply #13 on: November 03, 2018, 06:04:44 am »
project1.lpr(130,18) Error: Illegal expression
Code: Pascal  [Select]
  1. const
  2.   OS_USER_NAME = ;
You have to specify a username for a valid path to the EMPLOYEE.FDB file. This file is attached to the archive in the second post of this topic.

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus