Friday, 18 December 2020
  33 Replies
  1.3K Visits
  Subscribe
Hello,
I activated the watchdog system to ensure long time connections on my services.
Everything works great... but sometimes the watchdog does not work properly.
I have these properties set in the project:

...
FMQTT: TsgcWSPClient_MQTT;
FClient: TsgcWebSocketClient;

...
FClient.NotifyEvents := TwsNotifyEvent.neNoSync; // I use multithreaded application

FMQTT.HeartBeat.Enabled := True;
FMQTT.HeartBeat.Interval := 5;

FClient.WatchDog.Enabled := True;
FClient.WatchDog.Attempts := 0;
FClient.WatchDog.Interval := 10;

// I don't remember why I use this... :P
FClient.Options.CleanDisconnect := True;
...
FMQTT.OnError := wsClientError;
FMQTT.OnException := wsClientException;
FMQTT.OnDisconnect := wsClientDisconnect;
FMQTT.OnConnect := wsClientConnect;
FMQTT.OnMQTTPing := wsClientPing;
...
procedure TBroadcastManager.wsClientError(Connection: TsgcWSConnection; const Error: string);
begin
DoLog('wsClient Error: ' + Error, TLogType.Error);
end;
...
procedure TBroadcastManager.wsClientException(Connection: TsgcWSConnection; E: Exception);
begin
DoLog(Format('wsClient Exception: %s (%s)', [E.Message, E.ClassName]), TLogType.Error);
end;
...
procedure TBroadcastManager.wsClientPing(Connection: TsgcWSConnection);
begin
DoLog('Ping', TLogType.Debug);
end;
...
procedure TBroadcastManager.wsClientDisconnect(Connection: TsgcWSConnection; Code: Integer);
begin
DoLog(Format('wsClient Disconnected: %d', [Code]), TLogType.Error);
end;
...
procedure TBroadcastManager.wsClientConnect(Connection: TsgcWSConnection);
begin
DoLog('wsClient Connected', TLogType.Info);
end;
...

The "Ping" message in my logs appears regularly but sometimes it disappear. At this point (ping disappear) I see a "Disconnected" message and after 10 seconds a "Connected" message appear because the watchdog does his job.
In the case of this post I see the "Ping" message disappear and NEVER the "Disconncted" or "Connected" messages appear in the log (Example in "Schermata da 2020-12-18 11-17-14.png" attachment).
I never get exceptions or errors from the "onException" or "onError", so I don't know what happens.

The MQTT Broker is on the same machine of my project.

The LAN is very stable, but in this case I use "127.0.0.1" for communication.

How can I catch this strange issue?
Why in the 95% cases the watchdog works really fine and in the other 5% are there these issues?

I really need help.

Thanks
Eddy