Skip to content

Memory leak with Renci.SSHNet 2016.0.0 / FEATURE_SOCKET_EAP #133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sorenhjarlvig opened this issue Dec 15, 2016 · 2 comments
Closed

Memory leak with Renci.SSHNet 2016.0.0 / FEATURE_SOCKET_EAP #133

sorenhjarlvig opened this issue Dec 15, 2016 · 2 comments
Assignees

Comments

@sorenhjarlvig
Copy link

Renci is leaking SocketAsyncEventArgs objects when compiled with the FEATURE_SOCKET_EAP flag (seems to be the default build configuration). When compiled without FEATURE_SOCKET_EAP the leak goes away (naturally).
Perhaps this is caused by the use of the SetBuffer-method which according to http://codefruits.blogspot.dk/2013/03/memory-leak-in-c-net-sockets.html must be nulled (SetBuffer(null, 0, 0)) to be garbage collected correctly.
For some reason we didn't see this leak on Windows Server 2008 but when we recently moved our production to Windows Server 2012 the Windows NT service using Renci.SSHNET started to leak 100 MiB a day.

@drieseng
Copy link
Member

Can you try using version 2016.1.0-beta1?
I did some minor fixes in that area.

If you can still reproduce the leak, please provide a small repo.

Thx!

@sorenhjarlvig
Copy link
Author

I can confirm that 2016.1.0-beta1 seems to have fixed this issue.
For reference the leak can be reproduced on 2016.0.0 simply by running:

class Program
{
static void Main(string[] args)
{
using (
var sftpClient = new SftpClient("xxtest-server", "myuser",
new PrivateKeyFile("test.key")))
{
sftpClient.Connect();
var files = sftpClient.ListDirectory("/test");
Console.WriteLine(files.Count());
sftpClient.Disconnect();
}
GC.Collect();
GC.WaitForPendingFinalizers();
Console.ReadLine(); // Create memory dump at this point and check for SocketAsyncEventArgs instances
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants