You are not logged in.
Pages: 1
In my app, server is released in this way:
with TSQLite3HttpService.CreateAsConsole do
try
DoStart(nil);
writeln(#10'Background server is running.'#10);
writeln('Press [Enter] to close the server.'#10);
ConsoleWaitForEnterKey; // ReadLn if you do not use main thread execution
exit;
finally
Free;
end
During server closing (only when the client is still trying to communicate with server), I have very often strange error in 3 ways (i think it is all related to some mORMot logic bug):
1 is raised in TSQLHttpServer.HttpThreadTerminate > TSQLRestServer.EndCurrentThread, line 38290 :
if Sender.ThreadID<>CurrentThreadId then
raise ECommunicationException.CreateUTF8(
'%.EndCurrentThread(%.ID=%) should match CurrentThreadID=%',
[self,Sender,Sender.ThreadID,CurrentThreadId]);
2 VarRecToTempUTF8 in SynCommons - SIGSEGV for this:
vtObject: begin
if V.VObject<>nil then begin
Res.Text := PUTF8Char(PPointer(PPtrInt(V.VObject)^+vmtClassName)^)+1;
3 for procedure in RTL - TThread.SysDestroy; / TThread.Synchronize; (classes module)
always is raised randomly one of above errors. In Delphi all works fine...
This time I have no idea what is wrong :\
best regards,
Maciej Izak
Offline
Sounds like if a class instance is released twice, or not released in the expected order.
Try to run the server with FastMM4 FullDebugMode, which would help identify the problem.
See http://wiert.me/2009/07/29/delphi-fastm … roduction/
Offline
Sounds like if a class instance is released twice, or not released in the expected order.
Try to run the server with FastMM4 FullDebugMode, which would help identify the problem.
See http://wiert.me/2009/07/29/delphi-fastm … roduction/
That would be nice but FastMM4 don't work for FPC Windows target . I can't test it for Linux, the linux version of my server is in progress :\
best regards,
Maciej Izak
Offline
All is fine in Delphi. One small detail - in Delphi I need to press sometimes few times [enter] to close server, and even with this, closing is a little delayed (some threads locks?) during in fpc I need to press only one [enter] and server is released immediatly.
best regards,
Maciej Izak
Offline
fHttpServer.Terminate;
fHttpServer.WaitFor;
in destructor TSQLHttpServer.Destroy; in mORMotHttpServer before
FreeAndNil(fHttpServer);
fixes the problem for FPC.
Last edited by hnb (2016-01-21 12:12:26)
best regards,
Maciej Izak
Offline
Alternatively can be used this patch (SynCrtSock.pas):
destructor THttpApiServer.Destroy;
var i: integer;
begin
{.$ifdef LVCL}
Terminate; // for Execute to be notified about end of process
WaitFor;
{.$endif}
best regards,
Maciej Izak
Offline
I've overriden the TSynThread.Destroy method so that it calls Terminate and WaitFor, as TThread.Destroy in Delphi RTL.
It should fix the problem at higher level.
See http://synopse.info/fossil/info/265f6a043b
Offline
Yup it helps. I've created related bug report: http://bugs.freepascal.org/view.php?id=29470 (could you add some comment on bugtracker?)
In FPC is called Terminate and WaitFor but in other conditions (SysDestroy method):
if FHandle<>0 then
begin
{ Don't check Suspended. If the thread has been externally suspended (which is
deprecated and strongly discouraged), it's better to deadlock here than
to silently free the object and leave OS resources leaked. }
if not FFinished {and not Suspended} then
begin
Terminate;
{ Allow the thread function to perform the necessary cleanup. Since
we've just set Terminated flag, it won't call Execute. }
if FInitialSuspended then
Start;
WaitFor;
end;
end;
best regards,
Maciej Izak
Offline
Yes, works like a charm .
best regards,
Maciej Izak
Offline
Other good news: even "[Enter]" action to close server in console is now delayed as in Delphi Same behavior, both for Delphi and FPC.
best regards,
Maciej Izak
Offline
Pages: 1