#1 2018-12-14 06:57:36

edwinsn
Member
Registered: 2010-07-02
Posts: 1,215

How to identify threads started by mORMot server?

Assuming in a desktop program we have a mORMot server and a bunch of clients.
There will be 2 types of background threads in the program:
A - the server threads started by mORMot server when serving client requests.
B - the other ordinary threads started by the program.

The question is how to distinguish A from B?
I need this info to make sure the mORMot engine will log ONLY errors caused by the engine /db itself, but not errors caused in my other ordinary threads, by utilizing `SQLite3Log.Family.OnBeforeException`.

This is kind of a continued discussion of To allow ignoring exceptions with code, but I decided to post it separately to make things clearer.

Thanks.


Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.

Offline

#2 2018-12-14 09:00:23

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,240
Website

Re: How to identify threads started by mORMot server?

Every thread is named.
I have added aThreadName parameter to TSynLogFamily.OnBeforeException callback.
See https://synopse.info/fossil/info/80a92148c9

So you should be able to identify the thread context it runs on by checking the name.
Note that depending on the communication mean used (socket/http.sys/pipe), the thread names won't be the same.

Another (perhaps easier) option may be to define a global boolean threadvar, then set it to true on the withException threads.

Offline

#3 2018-12-14 14:30:04

edwinsn
Member
Registered: 2010-07-02
Posts: 1,215

Re: How to identify threads started by mORMot server?

Great! Thanks for your quick reaction, as aways smile

But how the mMORMot threads are named? Do they have a fixed prefix or something like that? I did a quick look at the source without a successful finding... Thanks.

Last edited by edwinsn (2018-12-14 14:32:40)


Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.

Offline

#4 2018-12-14 16:27:03

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,240
Website

Re: How to identify threads started by mORMot server?

Enable the logs, and you will find the thread names at the start of each thread, and in the LogView tool, in the "Thread" list.

Offline

#5 2018-12-16 13:07:19

edwinsn
Member
Registered: 2010-07-02
Posts: 1,215

Re: How to identify threads started by mORMot server?

@ab,
Done as you instructed, see attached screenshot, not sure how to interpret the names...
2018-12-16-21h00-02.png

And I explored the source and found:

constructor TSQLRestThread.Create(aRest: TSQLRest;
  aOwnRest, aCreateSuspended: boolean);
begin
...
  if fThreadName='' then
    FormatUTF8('% %',[self,fRest.Model.Root],fThreadName);
...
end;

So is TSQLRestThread.Create where the mORMot server threads are created and named?

Thanks.


Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.

Offline

#6 2018-12-16 16:52:58

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,240
Website

Re: How to identify threads started by mORMot server?

Your sample doesn't have any server thread.

Enable the logs on a http server application, and you will see.

Offline

#7 2018-12-17 02:56:34

edwinsn
Member
Registered: 2010-07-02
Posts: 1,215

Re: How to identify threads started by mORMot server?

Ah yes! Discovered log entries such as "SetThreadName 000026BC=TSQLHttpServer 80/root THttpApiServer". Thanks.


Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.

Offline

Board footer

Powered by FluxBB