Quantcast
Channel: sshnet Discussions Rss Feed
Viewing all articles
Browse latest Browse all 1729

New Post: Channel sessions not cleaning up (Avoiding Memory Leaks)

$
0
0
I have an application which requires very long term execution. It creates a series of SshCommand objects (Each with a specific command) then executes those (using command.execute()) once every few seconds for multiple weeks. The string results are used to populate various parsers and GUI elements.

I have not been able to isolate the reasons, but what I see are millions of left over ChannelSession objects resulting in a system crash (Out of memory).

I suspect I simply am not using the library correctly since there's no mention of this in recent discussions. Is there a good reference example of how to use the library to perform long term polling (Via SshCommand)?

Generally, my technique is:
  • Create a ConnectionInfo object conn
  • Create a SshClient(conn) object client
  • Call client.Connect()
  • Add SshCommand (s) to client using client.CreateCommand()
  • Periodically execute the SshCommands using command.Execute()
  • When the program is done, call client.Disconnect() and client.Dispose()
In WinDbg.exe, I see persistent ChannelSession objects which should have been garbage collected. Included with these are many events such as AutoReset and ManualReset events.

If my technique is correct, why is ChannelSession not being garbage colledted after each Execute()? The EndExecute() method looks like it should be Closing the channel:
        public string EndExecute(IAsyncResult asyncResult)
        {
            if (this._asyncResult == asyncResult && this._asyncResult != null)
            {
                lock (this._endExecuteLock)
                {
                    if (this._asyncResult != null)
                    {
                        //  Make sure that operation completed if not wait for it to finish
                        this.WaitHandle(this._asyncResult.AsyncWaitHandle);

                        if (this._channel.IsOpen)
                        {
                            this._channel.SendEof();

                            this._channel.Close();
                        }

                        this._channel = null;

                        this._asyncResult = null;

                        return this.Result;
                    }
                }
            }
Thanks,

Robert

Viewing all articles
Browse latest Browse all 1729


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>