You are not logged in.
Pages: 1
Hi there. I use callbacks and services via interfaces and websockets. Schematically, the code looks like this:
IBoss = interface(IInvokable)
function Manager1:IManager1; // create or return Manager1
function Manager2:IManager2; // create or return Manager2
end;
...
destructor TBoss.Destroy;
begin
fMng2 := nil;
fMng1 := nil;
inherited;
end;
...
//The difference between Manager1 and Manager2 in services. Therefore, the schematic code is for one only.
IManager1 = interface(IInvokable)...
TManager1 = class(TInterfacedObjectWithCustomCreate, IManager1)
...
fMService : IMService1; // interface(IServiceWithCallbackReleased)
fMCallback : IMCallback1;
fClient : TSQLRest;
...
end;
TMCallback1 = class(TInterfacedCallback, IMCallback1)
private
fMng:TManager1;
public
constructor Create(Manager:TManager1; aRest: TSQLRest; const aGUID: TGUID); reintroduce;
...
end;
constructor TManager1.Create;
begin
inherited Create;
fClient := TRestClient.Instance.Client;
fMService := fClient.Service<IMService1>;
fMCallback := TMCallback1.Create(Self, fClient, IMCallback1);
fMService.Subscribe(fMCallback);
...
end;
destructor TManager1.Destroy;
begin
fMCallback := nil;
fMService := nil;
...
inherited;
end;
When the program completes work with the "Boss", the following code is executed
...
Boss := nil;
TRestClient.Instance.Disconnect;
...
And... The session closes faster than the server has time to perform the required actions related to the CallbackRelease.
The log looks something like this:
15250718 + mORMotHttpClient.TSQLHttpClientWebsockets(03986e90).Callback svc/CacheFlush/_callback_
15250718 + mORMotHttpClient.TSQLHttpClientWebsockets(03986e90).InternalURI POST
15250718 trace mORMotHttpClient.TSQLHttpClientWebsockets(03986e90) InternalRequest POST calling THttpClientWebSockets(039ec450).Request
15250718 clnt mORMotHttpClient.TSQLHttpClientWebsockets(03986e90) POST svc/CacheFlush/_callback_?session_signature=66ab3c2d00014be19865d723 status=200 len=0 state=0
15250718 - 00.000.022
15250718 ret mORMotHttpClient.TSQLHttpClientWebsockets(03986e90) POST result=200 resplen=0
15250718 - 00.000.032
15250718 trace mORMotHttpClient.TSQLHttpClientWebsockets(03986e90) SessionClose: notify server
15250718 + mORMotHttpClient.TSQLHttpClientWebsockets(03986e90).CallBackGet svc/Auth?UserName=Admin&Session=1722498093
15250718 + mORMotHttpClient.TSQLHttpClientWebsockets(03986e90).InternalURI GET
15250718 trace mORMotHttpClient.TSQLHttpClientWebsockets(03986e90) InternalRequest GET calling THttpClientWebSockets(039ec450).Request
15250719 + TSVCServer(03976930).URI GET svc/Auth?UserName=Admin&Session=1722498093&session_signature=66ab3c2d00014be10a815db5 in=0 B
15250719 call TSVCServer(03976930) Auth UserName=Admin&Session=1722498093&session_signature=66ab3c2d00014be10a815db5
15250719 auth TSVCServer(03976930) Deleted session Admin:1722498093/1 from /2
15250719 srvr TSVCServer(03976930) Admin GET svc/Auth Method=200 out=0 B in 92us
15250719 - 00.000.110
15250719 + TSVCServer(03976930).URI POST svc/CacheFlush/_callback_?session_signature=66ab3c2d00014be19865d723 in=22 B
15250719 auth mORMot.TSQLRestRoutingREST(02f6eea0) AuthenticationFailed(afInvalidSignature) for svc/CacheFlush/_callback_?session_signature=66ab3c2d00014be19865d723 (session=1722498093)
15250719 debug TSVCServer(03976930) TSQLRestRoutingREST.Error: { "errorCode":403, "errorText":"Authentication Failed: Invalid signature (0)" }
15250719 srvr TSVCServer(03976930) POST svc/CacheFlush ?=403 out=82 B in 35us
15250719 - 00.000.047
15250719 + TSVCServer(03976930).URI POST svc/CacheFlush/_callback_?session_signature=66ab3c2d00014be19865d723 in=26 B
15250719 auth mORMot.TSQLRestRoutingREST(02f6eea0) AuthenticationFailed(afInvalidSignature) for svc/CacheFlush/_callback_?session_signature=66ab3c2d00014be19865d723 (session=1722498093)
15250719 debug TSVCServer(03976930) TSQLRestRoutingREST.Error: { "errorCode":403, "errorText":"Authentication Failed: Invalid signature (0)" }
15250719 srvr TSVCServer(03976930) POST svc/CacheFlush ?=403 out=82 B in 23us
15250719 - 00.000.034
15250719 clnt mORMotHttpClient.TSQLHttpClientWebsockets(03986e90) GET svc/Auth?UserName=Admin&Session=1722498093&session_signature=66ab3c2d00014be10a815db5 status=200 len=0 state=0
15250719 - 00.013.979
15250719 - 00.013.983
15250719 info mORMotHttpClient.TSQLHttpClientWebsockets(03986e90) TSQLRest.Destroy svc
15250720 trace mORMotHttpClient.TSQLHttpClientWebsockets(03986e90) TInterfacedObjectFakeClient(0449c7a0).Destroy IMService1
15250720 trace mORMotHttpClient.TSQLHttpClientWebsockets(03986e90) TInterfacedObjectFakeClient(0449cab8).Destroy IMService2
15250720 trace mORMotHttpClient.TSQLHttpClientWebsockets(03986e90) InternalClose: fSocket.Free
15250721 trace TSVCServer(03976930) EndCurrentThread(TWebSocketServerResp) ThreadID=3060 ThreadCount=0
"Sleep(100)" after "Boss:=nil" helps, but it's not the ideal way. Is there any way to tell the client that the server has done its job and you can close the connection?
Offline
Pages: 1