Shutdown of Application when using Echo

Hey,

i've got a problem where i don't find a proper solution.
I got two XData/Sphinx/Echo Servers. One is installed onto our Webserver, the other on a local Machine.
The two applications are similiar except for the Databases they're accessing and that the Application on the local machine will pull and push changes to the webserver.
When i trigger the Replication Process manually, everything works fine.
But when i use the TSparkleTimer approach from the EchoDemo i have the problem that the Application on the local Machine shuts down, without any error Messages. It runs for hours properly but at one point it simply shut down.

procedure TServerContainer.StartEchoServer;
var
  EchoModule: TEchoServerModule;
  Pool: IDBConnectionPool;
  NodeManager: IEchoNodeManager;
  Conn: IDBConnection;
begin
  if Assigned(SparkleEchoServer) then
     Exit;

  SparkleEchoServer := THttpSysServer.Create;

  // Echo Server
  Pool := AureliusConnection.GetPoolInterface;
  EchoModule := TEchoServerModule.Create(
    Setting.WebAdresse.AsUnicodeString+':'+IntToStr(Setting.WebPort)+'/tms/echo', Pool);
  SparkleEchoServer.AddModule(EchoModule);

  Echo := TEcho.Create(Pool);

  // Create regular tables and fields of the application
  Conn := Echo.Pool.GetConnection;
//  TDatabaseManager.Update(Conn);
  // Create tables and fields for TMS Echo usage
  TDatabaseManager.Update(Conn, TEcho.Explorer);
  Conn := nil; // Free reference

  // Get the NodeManager instance
  NodeManager := Echo.GetNodeManager;

  // If SelfNode is already defined, no need to define it again
  if NodeManager.SelfNode = nil then
  begin
    // SelfNode is not defined, so let's create a Node instance with the name
    // specified by the DBName property ("client1", "client2", "server" in the case
    // of our demo application. It can be any string value, it just needs
    // to be unique among all other databases being replicated.
    NodeManager.CreateNode(Setting.NodeName.AsUnicodeString);

    // Now define this newly created node as the SelfNode
    NodeManager.DefineSelfNode(Setting.NodeName.AsUnicodeString);
    Echo.GetRemoteNode(Setting.WebAdresse.AsUnicodeString+':'+IntToStr(Setting.WebPort)+'/tms/echo').RegisterNode;
  end;

  Timer := TSparkleTimer.Create(
    procedure(Echo: TObject)
    begin
      if (Setting.Mode.AsUnicodeString='Lokaler Server') then
        begin
          TEcho(Echo).GetRemoteNode(Setting.WebAdresse.AsUnicodeString+':'+IntToStr(Setting.WebPort)+'/tms/echo').Push;
          TEcho(Echo).GetRemoteNode(Setting.WebAdresse.AsUnicodeString+':'+IntToStr(Setting.WebPort)+'/tms/echo').Pull;
        end;
      TEcho(Echo).BatchLoad;
      TEcho(Echo).Route;
    end,
    Echo, 5000, TTimerType.Periodic);


  SparkleEchoServer.Start;
end;

Now i got two Questions:

  1. Shall i make the Timing of the Timer bigger?
  2. Is there a simple way to receive Error Logs from the Echo Shutdown?

Kind regards,

One thing you should do (not sure if that's the reason of shutdown, though) is to avoid the timer method executes twice simultaneously. Thus, make sure to create some global flag to check that in the timer, for example:

  Timer := TSparkleTimer.Create(
    procedure(Echo: TObject)
    begin
      if FRunningTimer then Exit;
      FRunningTimer := True;
      try
        if (Setting.Mode.AsUnicodeString='Lokaler Server') then
          begin
            TEcho(Echo).GetRemoteNode(Setting.WebAdresse.AsUnicodeString+':'+IntToStr(Setting.WebPort)+'/tms/echo').Push;
            TEcho(Echo).GetRemoteNode(Setting.WebAdresse.AsUnicodeString+':'+IntToStr(Setting.WebPort)+'/tms/echo').Pull;
          end;
        TEcho(Echo).BatchLoad;
        TEcho(Echo).Route;
      finally
        FRunningTimer := False;
      end;
    end,
      Echo, 5000, TTimerType.Periodic);

About your second question, I'm not sure I understand it, but if you mean about this abnormal shutdown, it's hard to tell why it happens and the point it happens. The logs should be set by you in your app, Echo itself is not forcing a shutdown.

I think your approach with the "don't execute timer when it's still handling the operation" did the trick.
Since i made the changes in the Timer Code it didn't crashed once.
Thanks again for the good support

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.