#1 2019-03-08 03:03:58

cybexr
Member
Registered: 2016-09-14
Posts: 78

potential thread-sync bug with SOA interface service

Hi ab,   I'm trying to add a new restserver which exposes interface service running in Mainthread.  But if client call the new service, server will hang on this request till timeout.

Server side compiled with FPC(tried with: 3.2.0-beta-r41498 & 3.1.1-r39235 ) + mormot (latest code on github) running on Linux x64.

server code like this:

      aServer.ServiceRegister(TServiceRemoteSQL,[TypeInfo(IRemoteSQL)], sicPerThread).SetOptions([], []);
      bServer.ServiceRegister(TServiceRemoteTS,[TypeInfo(IRemoteTS)], sicClientDriven).SetOptions([], [optExecInMainThread,optFreeInMainThread]);
      aHTTPServer := TSQLHttpServer.Create(PORT_NAME,[aServer, bServer]);

Request URL:
http://172.16.13.122:6610/boot/RemoteTS … 595fe9b2ca   //this request fine
http://172.16.13.122:6610/boot/RemoteTS … 59a13f2640  //this request will hang


server log :

20190308 02331860  # srvr  	mORMot.TSQLRestServerFullMemory(00007F9CF08E4D30) User 172.18.0.3 POST root/RemoteSQL.ExeBin Interface=200 out=397 B in 3.95ms
20190308 02331860  #  -    00.004.030
20190308 02331901  #  +    mORMot.TSQLRestServerFullMemory(00007F9CF08E6DF0).URI POST boot/RemoteTS._instance_?session_signature=6a48c0cf007f71595fe9b2ca in=2 B
20190308 02331901  # auth  	mORMot.TSQLRestRoutingREST(00007F9CEE8F5D30) User/1783152847 172.18.0.3
20190308 02331901  # debug 	mORMot.TSQLRestServerFullMemory(00007F9CF08E6DF0) TServiceFactoryServer.InternalInstanceRetrieve: Adding RemoteTS(00007F9CF07B2600) instance (id=1) count=1
20190308 02331901  # srvr  	mORMot.TSQLRestServerFullMemory(00007F9CF08E6DF0) User 172.18.0.3 POST boot/RemoteTS._instance_ Interface=200 out=12 B in 124us
20190308 02331901  # ret   	mORMot.TSQLRestServerFullMemory(00007F9CF08E6DF0) {"result":1}
20190308 02331901  #  -    00.000.234
20190308 02331903  #  +    mORMot.TSQLRestServerFullMemory(00007F9CF08E6DF0).URI POST boot/RemoteTS.TransactionStart/1?session_signature=6a48c0cf007f7159a13f2640 in=2 B
20190308 02331903  # auth  	mORMot.TSQLRestRoutingREST(00007F9CEE8F5D30) User/1783152847 172.18.0.3
20190308 02334961  $ info  SetThreadName 00007F9CEFB17700=TSQLHttpServer 8888/root boot TSynThreadPoolSubThread
20190308 02334961  $ trace mORMot.TSQLRestServerFullMemory(00007F9CF08E4D30) BeginCurrentThread(TSynThreadPoolSubThread) root=root ThreadID=00007F9CEFB17700 ThreadCount=3
20190308 02334961  $ trace mORMot.TSQLRestServerFullMemory(00007F9CF08E6DF0) BeginCurrentThread(TSynThreadPoolSubThread) root=boot ThreadID=00007F9CEFB17700 ThreadCount=3
20190308 02334961  $  +    mORMot.TSQLRestServerFullMemory(00007F9CF08E6DF0).URI POST boot/RemoteTS._free_/1?session_signature=6a48c0cf007f71d255b6dea8 in=2 B
20190308 02334961  $ auth  	mORMot.TSQLRestRoutingREST(00007F9CED18C970) User/1783152847 172.18.0.3
20190308 02342161  % info  SetThreadName 00007F9CEFA96700=TSQLHttpServer 8888/root boot TSynThreadPoolSubThread
20190308 02342161  % trace mORMot.TSQLRestServerFullMemory(00007F9CF08E4D30) BeginCurrentThread(TSynThreadPoolSubThread) root=root ThreadID=00007F9CEFA96700 ThreadCount=4
20190308 02342161  % trace mORMot.TSQLRestServerFullMemory(00007F9CF08E6DF0) BeginCurrentThread(TSynThreadPoolSubThread) root=boot ThreadID=00007F9CEFA96700 ThreadCount=4
20190308 02342161  %  +    mORMot.TSQLRestServerFullMemory(00007F9CF08E4D30).URI GET root/Auth?UserName=User&Session=520179731&session_signature=1f015013007f724f984fdeb5 in=0 B
20190308 02342161  % auth  	mORMot.TSQLRestRoutingREST(00007F9CED124BF0) User/520179731 172.18.0.3
...

20190308 02405509  %  +    mORMot.TSQLRestServerFullMemory(00007F9CF08E4D30).URI GET root/timestamp in=0 B
20190308 02405509  % srvr  	mORMot.TSQLRestServerFullMemory(00007F9CF08E4D30)  172.18.0.3 GET root/timestamp Method=200 out=12 B in 39us
20190308 02405509  % ret   	mORMot.TSQLRestServerFullMemory(00007F9CF08E4D30) 135502113335
20190308 02405509  %  -    00.000.133

Offline

#2 2019-03-08 08:42:16

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

Re: potential thread-sync bug with SOA interface service

Are you sure Application.ProcessMessages (or something else needed by TThread.Synchronize) is actually called in your main thread?

Offline

#3 2019-03-08 09:34:03

cybexr
Member
Registered: 2016-09-14
Posts: 78

Re: potential thread-sync bug with SOA interface service

uh , my low level bug,  thank you ab. 

used Syncommons.ConsoleWaitForEnterKey , which will give mainthread chance to work on windows,  so works well on windows; but this function just Readln on linux, so mainthread is starved to end.
And is there some util-function can do this work ?

Offline

#4 2019-03-08 11:10:02

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,539
Website

Re: potential thread-sync bug with SOA interface service

Offline

#5 2019-03-09 08:28:43

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

Re: potential thread-sync bug with SOA interface service

Hello mpv, interesting, I assume you mean (https://www.freepascal.org/docs-html/rt … pause.html)

Do you know similar things exist for Delphi for Windows smile


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

Offline

#6 2019-03-09 09:36:24

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,539
Website

Re: potential thread-sync bug with SOA interface service

I don't found analogue (signals on Windows is very limited)

Offline

#7 2019-03-12 06:52:32

cybexr
Member
Registered: 2016-09-14
Posts: 78

Re: potential thread-sync bug with SOA interface service

Thanks mpv,  your code works fine , it helps gracefully quit app.  And fpPause will just sleep mainthread but not respond to later sub-thread synchorize ,  and CheckSynchronize(10) will do the work.

Offline

Board footer

Powered by FluxBB