Delphi Service Application crashing after several hours - WeOnlyDo Discussion board

Delphi Service Application crashing after several hours (wodSFTP / wodSFTP.NET / wodSFTPdll)

by Gloegg, Monday, August 11, 2014, 20:31 (1196 days ago) @ wodSupport

Hi,
it happened again. this time after 4 days and 3 hours of program uptime.

The Exception was thrown by sftp.GetFiles(...) and was handled but then the application stopped.

I don't know what to try at this point.

I attached the current source code:
-CheckServerForNewFiles is called every minute by a TTimer
-sftpLoopItem is the event of the wodSFTP
-RemoveFilesFromServer deletes every remote file that was not skipped by sftpLoopItem

these methods are defined in a single TDataModule which is created when the service application is started and freed when the service is stopped.

procedure TdmTransfer.CheckServerForNewFiles;
var
  filenames: TStringDynArray;
  bugreport: string;
  fn: string;
  sftp: TwodSFTPCom;
begin
  try
    fFilesToBeRemoved.Clear;
    CoInitialize(nil);
    sftp := TwodSFTPCom.Create(self);
    sftp.Connect;
    sftp.LicenseKey := 'myLicenseKey';
    sftp.Hostname := 'myHostname';
    sftp.Login := 'myUsername';
    sftp.Port := 22;
    sftp.Password := 'myPassword';
    sftp.Blocking := true;
    sftp.Authentication := authPassword;
    sftp.ProxyType := ProxyNone;
    sftp.OnLoopItem := sftpLoopItem;

    sftp.Connect1;
    sftp.RemotePath := TSettings.Instance.RemotePath;
    sftp.LocalPath := 'c:\temp\download\';
    sftp.GetFiles(sftp.LocalPath, sftp.RemotePath, 1);

    filenames := TDirectory.GetFiles('c:\temp\download\', '*.XML');
    if length(filenames) > 0 then
    begin
      MoveFilesToImport(filenames);
      RemoveFilesFromServer(sftp);
    end
    else
      TLogger.AddLog('No files found');
    sftp.Disconnect1;
    sftp.Free;
    CoUninitialize;
  except
    on ex: Exception do
    begin
      bugreport := CreateBugReport(etNormal, ex);
      AddLog(bugreport);
    end;
  end;
end;

procedure TdmTransfer.RemoveFilesFromServer(aSFTP: TwodSFTPCom);
var
  fn: string;
begin
  TLogger.AddLog('Deleting files from server');
  for fn in fFilesToBeRemoved do
  begin
    TLogger.AddLog('  ' + fn);
    aSFTP.DeleteFile(fn);
  end;
  fFilesToBeRemoved.Clear;
end;

procedure TdmTransfer.sftpLoopItem(ASender: TObject; var LocalFile, RemoteFile: WideString; ItemType: TOleEnum;
  var Skip: WordBool);
begin
  Skip := pos('.XML', string(RemoteFile)) <= 0;
  if not Skip then
    fFilesToBeRemoved.Add(RemoteFile);
end;

Complete thread: