Apparent memory leak.

Advertisement

SFF_Dan
Joined:
Posts:
2
Location:
Newcastle-Upon_tyne

Apparent memory leak.

Summary: Operating System - Windows 2008 RC2. Application complied explicitly as x64, on .NET 4.6.1.

Firstly, I apologise in advance that do not feel I am able to provide much detailed debugging information of what I'm seeing at this stage, and would welcome any suggestions as to what I could do, to improve this.

I'm running the latest version of the WinSCP .NET assembly to manage SFTP transfers via a Windows Forms program that uses a Timer built into its main form to open and close connections to various remote directories on various servers on a regular cycle. All this is controlled via entries in a MySQL table. Cycles are configurable per job, but are generally in the 1-2 minute range.

For legacy reasons, this is a VB .NET program and the connection code to try and create a usable connection job at the start of each work cycle looks like this:

        If Not SFTPclient.Opened Then
            Try
                Dim sessionoptions As New WinSCP.SessionOptions
                With sessionoptions
                    .UserName = curSubTaskRow.Item("task" & strTaskType & strClientTypeAbbrev & "FTPUser")
                    .Password = curSubTaskRow.Item("task" & strTaskType & strClientTypeAbbrev & "FTPPass")
                    .HostName = curSubTaskRow.Item("task" & strTaskType & strClientTypeAbbrev & "FTPHost")
                    .Protocol = WinSCP.Protocol.Sftp
                    .GiveUpSecurityAndAcceptAnySshHostKey = True 'Assume we can trust the remote server
                End With
                SFTPclient.Open(sessionoptions)
            Catch ex As Exception
                logEvent.writeLog(jobID, curTaskID, "Connection failed to FTP " & strClientType, "", ex.ToString, 0)
            End Try
        End If
        Return SFTPclient

As you can see, if the catch fails, it simply writes whatever the exception text was, into a MySQL database table.

After some hours or days of running, this starts catching errors of this type:

WinSCP.SessionLocalException: WinSCP process terminated with exit code 1. Error output was "Out of memory Please help us improving WinSCP by reporting the error on WinSCP support forum.". Response log file C:\Users\mp0018.System\AppData\Local\Temp\wscp0EB8.036AEBFA.tmp was not created. This could indicate lack of write permissions to the log f
older or problems starting WinSCP itself.
   at WinSCP.Session.Open(SessionOptions sessionOptions)
   at SFF2.workClass.FTPConnect(Session& SFTPclient, String strClientType, String strClientTypeAbbrev, String strTaskType) in C:\Application2\Application2\SuperFF\workClass.vb:line 1197

For what it is worth, the log file referred to in the error certainly never gets written, but the system seems to log other things, most of the time, in the same location, so I can't see how permissions are to blame. Line 1197 is just the "FTPclient.Open(sessionoptions)".

After a time, this message changes to:

System.ComponentModel.Win32Exception (0x80004005): The paging file is too small for this operation to complete
  at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
  at WinSCP.ExeSessionProcess.InitializeChild()
  at WinSCP.ExeSessionProcess.Start()
  at WinSCP.Session.Open(SessionOptions sessionOptions)
  at SFF2.workClass.FTPConnect(Session& SFTPclient, String strClientType, String strClientTypeAbbrev, String strTaskType) in C:\Application2\Application2\SuperFF\workClass.vb:line 1197

...some time after this the entire .NET program usually crashes.

At the moment I am currently catching the second error, and the machine is running at 2.38G of 4G of allocated RAM (although this is on a virtual server).

Also perhaps worth saying that, for legacy reasons, the .NET program is explicitly compiled as a 64 bit assembly. This is still a test build of this application (we are trying to move away from a previous version of the same code base that used the WeOnlyDoSFTP component, to do all this) I don't recall seeing these errors prior to upgrading to 5.11.2, but the program wasn't running under the load it is now, back then.

I don't expect much, at this stage, with what information I've provided so far, but will be happy to run any tests that you might suggest in the morning (UK time).

Reply with quote

Advertisement

SFF_Dan
Joined:
Posts:
2
Location:
Newcastle-Upon_tyne

Re: Apparent memory leak.

martin wrote:

Do you call .Dispose on SFTPclient, once you stop using it?

No, we don't. The guy who wrote the previous code simply had the WeOnlyDo object floating around as a sort of global - which is why the test, to see whether or not the equivalent WinSCP object already exists, is there at the start.

Explicitly opening and closing the object certainly seems a more sensible approach. So I could try rewriting it in that way, if you think it will improve matters.

Reply with quote

Advertisement

You can post new topics in this forum