View Issue Details

IDProjectCategoryView StatusLast Update
0032532FPCFCLpublic2019-12-05 15:55
ReporterCyraxAssigned ToMichael Van Canneyt 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
PlatformLinux x86_64OSArchOS Version3.17.4-1
Product Version3.1.1Product Buildr37441 
Target VersionFixed in Version3.3.1 
Summary0032532: Running more than one TDaemon class instances causes Access Violation exception to occur.
DescriptionAs in said in the summary, running than one TDaemon class instances (they run continuously until the project terminates) causes Access Violation exception to occur and trying to terminate the project graciously way (using TERM signal), the project wont stop running.
Steps To Reproduce0. Install LazDaemon package into Lazarus IDE.
1. Open attached project in Lazarus.
2. Compile project.
3. Open two terminal windows. In one terminal, run the daemon project. In another, try to terminate the running daemon project. E.g using this command : kill -TERM $(pgrep --list-full project1 | awk '{ print $1 }').
TagsNo tags attached.
Fixed in Revision43645.
FPCOldBugId
FPCTarget3.2.0
Attached Files
  • project1.tar.gz (2,153 bytes)
  • event-log.txt (271 bytes)
     [2017-10-11 12:26:15.942 Custom (0)] TDaemon2 execution start
     [2017-10-11 12:26:28.163 Info] Failed to start daemon TDaemon2 : Access violation
     [2017-10-11 12:26:28.164 Custom (0)] TDaemon1 execution start
     [2017-10-11 12:26:28.168 Custom (0)] TDaemon2 execution stop
    
    event-log.txt (271 bytes)
  • unix_daemonapp.diff (1,419 bytes)
    diff --git packages/fcl-extra/src/daemonapp.pp packages/fcl-extra/src/daemonapp.pp
    index cb55c41cc1..616fedf518 100644
    --- packages/fcl-extra/src/daemonapp.pp
    +++ packages/fcl-extra/src/daemonapp.pp
    @@ -56,6 +56,7 @@ Type
         Function Install : Boolean; virtual;
         Function UnInstall: boolean; virtual;
         Function HandleCustomCode(ACode : DWord) : Boolean; Virtual;
    +    procedure DoThreadTerminate(Sender: TObject);virtual;
       Public
         Procedure CheckControlMessages(Wait : Boolean);
         Procedure LogMessage(const Msg : String);
    @@ -694,7 +695,12 @@ begin
       Result:=False
     end;
     
    -Procedure TCustomDaemon.CheckControlMessages(Wait : Boolean);
    +procedure TCustomDaemon.DoThreadTerminate(Sender: TObject);
    +begin
    +  Self.FThread := NIL;
    +end;
    +
    +procedure TCustomDaemon.CheckControlMessages(Wait: Boolean);
     
     begin
       If Assigned(FThread) then
    diff --git packages/fcl-extra/src/unix/daemonapp.inc packages/fcl-extra/src/unix/daemonapp.inc
    index a33bf85991..c124e235f5 100644
    --- packages/fcl-extra/src/unix/daemonapp.inc
    +++ packages/fcl-extra/src/unix/daemonapp.inc
    @@ -167,9 +167,8 @@ begin
       Try
         T:=TDaemonThread.Create(FDaemon);
         T.FreeOnTerminate:=True;
    +    T.OnTerminate := @FDaemon.DoThreadTerminate;
         T.Resume;
    -    T.WaitFor;
    -    FDaemon.FThread:=Nil;
       except
         On E : Exception do
           FDaemon.Logmessage(Format(SErrDaemonStartFailed,[FDaemon.Definition.Name,E.Message]));
    
    unix_daemonapp.diff (1,419 bytes)

Activities

Cyrax

2017-10-11 11:52

reporter  

project1.tar.gz (2,153 bytes)

Cyrax

2017-10-11 11:53

reporter  

event-log.txt (271 bytes)
 [2017-10-11 12:26:15.942 Custom (0)] TDaemon2 execution start
 [2017-10-11 12:26:28.163 Info] Failed to start daemon TDaemon2 : Access violation
 [2017-10-11 12:26:28.164 Custom (0)] TDaemon1 execution start
 [2017-10-11 12:26:28.168 Custom (0)] TDaemon2 execution stop
event-log.txt (271 bytes)

Cyrax

2017-10-11 11:53

reporter  

unix_daemonapp.diff (1,419 bytes)
diff --git packages/fcl-extra/src/daemonapp.pp packages/fcl-extra/src/daemonapp.pp
index cb55c41cc1..616fedf518 100644
--- packages/fcl-extra/src/daemonapp.pp
+++ packages/fcl-extra/src/daemonapp.pp
@@ -56,6 +56,7 @@ Type
     Function Install : Boolean; virtual;
     Function UnInstall: boolean; virtual;
     Function HandleCustomCode(ACode : DWord) : Boolean; Virtual;
+    procedure DoThreadTerminate(Sender: TObject);virtual;
   Public
     Procedure CheckControlMessages(Wait : Boolean);
     Procedure LogMessage(const Msg : String);
@@ -694,7 +695,12 @@ begin
   Result:=False
 end;
 
-Procedure TCustomDaemon.CheckControlMessages(Wait : Boolean);
+procedure TCustomDaemon.DoThreadTerminate(Sender: TObject);
+begin
+  Self.FThread := NIL;
+end;
+
+procedure TCustomDaemon.CheckControlMessages(Wait: Boolean);
 
 begin
   If Assigned(FThread) then
diff --git packages/fcl-extra/src/unix/daemonapp.inc packages/fcl-extra/src/unix/daemonapp.inc
index a33bf85991..c124e235f5 100644
--- packages/fcl-extra/src/unix/daemonapp.inc
+++ packages/fcl-extra/src/unix/daemonapp.inc
@@ -167,9 +167,8 @@ begin
   Try
     T:=TDaemonThread.Create(FDaemon);
     T.FreeOnTerminate:=True;
+    T.OnTerminate := @FDaemon.DoThreadTerminate;
     T.Resume;
-    T.WaitFor;
-    FDaemon.FThread:=Nil;
   except
     On E : Exception do
       FDaemon.Logmessage(Format(SErrDaemonStartFailed,[FDaemon.Definition.Name,E.Message]));
unix_daemonapp.diff (1,419 bytes)

Cyrax

2017-10-11 11:55

reporter   ~0103353

Attached event log file and patch (unix_daemonapp.diff) to fix this issue.

Michael Van Canneyt

2019-12-05 15:55

administrator   ~0119627

Hm. This bug escaped my attention, otherwise I would have fixed it earlier.

Fix applied, also committed the test application in examples; Thank you very much!

Issue History

Date Modified Username Field Change
2017-10-11 11:52 Cyrax New Issue
2017-10-11 11:52 Cyrax File Added: project1.tar.gz
2017-10-11 11:53 Cyrax File Added: event-log.txt
2017-10-11 11:53 Cyrax File Added: unix_daemonapp.diff
2017-10-11 11:55 Cyrax Note Added: 0103353
2019-12-05 15:55 Michael Van Canneyt Assigned To => Michael Van Canneyt
2019-12-05 15:55 Michael Van Canneyt Status new => resolved
2019-12-05 15:55 Michael Van Canneyt Resolution open => fixed
2019-12-05 15:55 Michael Van Canneyt Fixed in Version => 3.3.1
2019-12-05 15:55 Michael Van Canneyt Fixed in Revision => 43645.
2019-12-05 15:55 Michael Van Canneyt FPCTarget => 3.2.0
2019-12-05 15:55 Michael Van Canneyt Note Added: 0119627