You are not logged in.
Hello
I have a mormot project and it works when I start it as a console app, (with /c parameter)
but when i start as a Service it does not work.
(Service user credentials same in both cases)
I have 2 servers running....
TSQLRESTServerHttpService = class(TServiceSingle)
public
aModel1: TSQLModel;
aModel2: TSQLModel;
aServer1: TSQLRestServer;
aServer2: TSQLRestServer;
aHTTPServer: TSQLHttpServer;
aHttpApiServer: THttpApiServer;
aServerEvents: TMyServerEvents;
aServiceFactoryServer: TServiceFactoryServer;
http_server_security: TSQLHttpServerSecurity;
server, db, user, pw: RawUTF8;
....
I create all model, restserver and httpserver in "DoStart" procedure.
The DB connection (MSSQL/oledb) is also created in dostart but it is owned by a global object (fprops)
It seems that, when starting as a service, DoStart will NOT be called (that is after ServicesRun)
Should i call dostart myself, as I do in the console mode?
What is the right place for creating model and server objects.
What is the right place for creating DB connection, same connection for all / separate connection for every connect/thread?
Any Ideas for where the error could be?
What is the best way to track it down?
Debugging is a little bit tricky because of the timeouts.
The model2,server2, httpApiServer works, it has no authentication and it serves a html login webpage. When I press "login" it calls model1,server1, httpServer for the authentication steps, timestamp and the next one's works, but the Connect ends with a timeout, no answer! This works when running in console mode!
(the structure of the project is "taken" from Sample 10, but we have several servers defined)
Best regards Kim Granlund
Errors from log when running as service:
when closing the service...
20190503 17164123 ! ERROR "EAssertionFailed(00A49A80)":"You should call TOleDBConnection.Free from the same thread which called its Create: i.e. call MyProps.EndCurrentThread from an THttpServerGeneric.OnHttpThreadTerminate event - see ticket 213544b2f5 (D:\\CbtProgsBDS\\Vcl\\Mormot\\SynOleDB.pas, line 2299)" stack trace API 00461266 0040475B
20190503 17164625 ! EXC EInvalidPointer ("Invalid pointer operation") at 00404715 stack trace API 0045F9B7 00405176 7C90327A 7C90E48A 00404715 0040475B 00659A90 0040475B 7C817077
Last edited by Kixemi (2019-05-04 17:31:30)
Offline
And many many many hours later... i found the reason why the program works in console mode but not as a service!
By removing this line of code:
aServiceFactoryServer.SetOptions([],[optExecInMainThread,optFreeInMainThread]);
The calls to my (server 2) aHttpApiServer worked OK, all the time.
After the first calls to (server 1) aHTTPServer timestamp, Auth... and then .Connect I did not get any response anymore!
In the middle of .Connect the server begun to "shut down" EndCurrentThread in the log in the middle of creating a new connection...
Thanks!
I hope this will help others with the same problem!
Perhaps somebody can tell the difference between the thread/mainthread handling in console versus service mode?
Now it works like a windows service shall do, and I can use it!
BUT! still I get an access violation shutting down the service!
from the log:
20190506 23184556 ! ERROR "EAssertionFailed(00A49A80)":"You should call TOleDBConnection.Free from the same thread which called its Create: i.e. call MyProps.EndCurrentThread from an THttpServerGeneric.OnHttpThreadTerminate event - see ticket 213544b2f5 (D:\\CbtProgsBDS\\Vcl\\Mormot\\SynOleDB.pas, line 2299)" stack trace API 00461266 0040475B
I dont know witch connection this refers to, one of the per-session specific db-connections or the connection i create in DoStart.
Offline
Did you try with opt*InBackgroundThread options instead?
In a service, there is no such thing as a "main thread".
ConsoleWaitForEnterKey() is executing the main thread option, but not in a service.
About the OleDB exception, it is clear you are releasing the connection not from the same thread as it is created.
You have to fix your code about that.
Offline
Now I got rid of the OleDB exception!
To be honest, I dont know where the fProps is released now, and I did not find any "opt*InBackgroundThread options" in the TServiceMethodOption....
but I did put
aServiceFactoryServer.SetOptions([],[optExecInPerInterfaceThread,optFreeInPerInterfaceThread])
and that works both for service mode and console mode! It also fixex a problem with running MSSQL queryes in transactions (begintrans, commit)
However this did not eliminate the error when releasing the OleDB....
then I changed all the .free (aModel.free, aServer.free fProps.free ....) to the FreeAndNil(aModel for ex) in the program, and that fixed that problem.
Seems that the "if pointer <> nil" is in use before releasing objects inside the factory.
Thanks!
Last edited by Kixemi (2019-05-08 10:11:28)
Offline