#1 2019-04-09 11:47:54

DarioPagliarini
Member
From: Soncino - Italy
Registered: 2019-04-09
Posts: 4

OnWebSocketsClosed not fired in last release.

I recompile my code after an upgrade of the repository and with the actual release the OnWebSocketsClosed event is not fired.

    Client := TSQLHttpClientWebsockets.Create(strHostName, strPortNumber, TSQLModel.Create([TSQLWatchDog]));

    Client.Model.Owner := Client;
    Client.WebSocketsUpgrade (TRANSMISSION_KEY);
    Client.OnWebSocketsClosed := OnWebSocketsClosed;

If I recompile with old release (from January 2019) the event is fired as expected.
Am I miss something?

(Compiler : Delphi 10.3 Community Edition)

Offline

#2 2019-04-09 16:00:39

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

Re: OnWebSocketsClosed not fired in last release.

I guess  Client.OnWebSocketsClosed := OnWebSocketsClosed should be set BEFORE Client.WebSocketsUpgrade.

Offline

#3 2019-04-10 05:31:20

DarioPagliarini
Member
From: Soncino - Italy
Registered: 2019-04-09
Posts: 4

Re: OnWebSocketsClosed not fired in last release.

Thanks for your quick reply.
I followed your suggestion but the result is the same, so I don't think it depends on the order of the two operations, also because otherwise it wouldn't work even with the previous version.

The behavior is different in the function TWebSocketProcessClientThread.Execute (in SynBidirSock.pas unit)
    Old Release: fProcess.ProcessLoop Exit with sockerror <> 0 and trigger the OnWebSocketsClosed event
    Current Release : fProcess.ProcessLoop  continue iteration (sockerror = 0)

I will try to investigate by myself, but any help is welcome.

Offline

#4 2019-04-11 10:49:41

Chaa
Member
Registered: 2011-03-26
Posts: 249

Re: OnWebSocketsClosed not fired in last release.

I have similar problem: TWebCrtSocketProcess.ProcessLoop does not properly detect network errors and not finished.
Instead, all requests completed with error "'Not Found' (404 - Network problem or request timeout)".

Offline

#5 2019-04-16 10:00:37

DarioPagliarini
Member
From: Soncino - Italy
Registered: 2019-04-09
Posts: 4

Re: OnWebSocketsClosed not fired in last release.

In SynCrtSock unit, function TCrtSocket.SockReceivePending return cspNoData in case of broken connection.
Previous release return cspDataAvailable that is correctly handled and generate the notification of OnWebSocketsClosed.
Something is not ok after the Select function call

res := Select(fSock+1,@fdset,nil,nil,@tv);
    if res<0 then
      result := cspSocketError else
      if (res>0) and(fdset.fd_count=1) and (fdset.fd_array[0]=fSock) and
         (IoctlSocket(fSock,FIONREAD,pending)=0) and (pending>0) then
        result := cspDataAvailable else
        result := cspNoData;

Offline

#6 2019-04-18 09:31:39

Chaa
Member
Registered: 2011-03-26
Posts: 249

Re: OnWebSocketsClosed not fired in last release.

I change function TWebSocketProcess.NotifyCallback so that it returns STATUS_NOTIMPLEMENTED when SendFrame failed, indicating that connection broken. Patch:

--- SynBidirSock.org
+++ SynBidirSock.pas
@@ -2435,8 +2435,10 @@ begin
   try
     if (i>2) and (WebSocketLog<>nil) then
       WebSocketLog.Add.Log(sllWarning,'NotifyCallback with fProcessCount=%',[i],self);
-    if not SendFrame(request) then
+    if not SendFrame(request) then begin
+      result := STATUS_NOTIMPLEMENTED;
       exit;
+    end;
     if aMode=wscBlockWithoutAnswer then begin
       result := STATUS_SUCCESS;
       exit;

You can try. If it helps, then we can create pull request.

Last edited by Chaa (2019-04-18 09:33:12)

Offline

#7 2019-04-23 14:29:13

DarioPagliarini
Member
From: Soncino - Italy
Registered: 2019-04-09
Posts: 4

Re: OnWebSocketsClosed not fired in last release.

I try your code but no luck in my case.
Unfortunately I have no time now for further investigation so I must stay on the January release.

Offline

Board footer

Powered by FluxBB