sshnet / sshnet/SSH.NET

SSHClient: ForwardedPortLocal: memory issue

Offen
#775 6 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
C#
Sterne
4.4k
Forks
993
Ø Merge
9 T. 21 Std.
Gemergte PRs (30 T.)
1

Beschreibung

Hello,

I am using the following code below. I call this ConnectSSH() every 5 seconds (as a test to see how it performs)
After I let this run a night, i see that the used memory increased significantly, and it keeps rising.

After some investigation on my own, i notice that when I remove the "forwardedportlocal" object, (so I don't make such an object, and I obviously don't start it) Then there is no memory issue. The client is created, and then disposed cleanly.
I can see this happening the diagnostic tool of visual studio.

I already added portfwld.stop() and portfwld.dispose() together with of course SshClient.disconnect() and SshClient.dispose()
but that did not help.

I made a version in vb.net and also one in c#, but the results are the same.

I also Commented the connection to the database to show that this is not the issue.

I hope someone can give me some insight of what is happening, or perhaps what I am doing wrong?

    class mySQLviaSHH
    {
        
        public void ConnectSSH()
        {
            using (var SSHClient = new SshClient("myhost", "administrator", "mypassword"))
            {
                try
                {
                    // Console.WriteLine("Trying SSH connection...")
                    SSHClient.Connect();

                    if (SSHClient.IsConnected)
                        Console.WriteLine("SSH connection is active");
                    else
                        Console.WriteLine("SSH connection has failed");

                    Console.WriteLine("Trying port forwarding...");

                    var portFwld = new ForwardedPortLocal("127.0.0.1", "127.0.0.1", 3306);
                    SSHClient.AddForwardedPort(portFwld);
                    portFwld.Start();

                    if (portFwld.IsStarted)
                        Console.WriteLine("Port forwarded: {0}", portFwld.ToString());
                    else
                        Console.WriteLine("Port forwarding has failed.");
                }
                catch (SshException e)
                {
                    Console.WriteLine("SSH client connection error: {0}", e.Message);
                }
                
            }
        }


    }
Public Sub ConnectSSH()
            Using SSHClient = New SshClient("myhost", "administrator", "mypassword")
                Try
                    Console.WriteLine("Trying SSH connection...")
                    SSHClient.Connect()

                    If SSHClient.IsConnected Then
                        Console.WriteLine("SSH connection is active")
                    Else
                        Console.WriteLine("SSH connection has failed")
                    End If

                    Console.WriteLine(vbCrLf & "Trying port forwarding...")

                    Dim portFwld = New ForwardedPortLocal("127.0.0.1", "127.0.0.1", 3306)
                    SSHClient.AddForwardedPort(portFwld)
                    portFwld.Start()

                    If portFwld.IsStarted Then
                        Console.WriteLine("Port forwarded: {0}", portFwld.ToString())

                        '        'Dim dbConnect As DBConnect = New DBConnect(portFwld.BoundHost, "wcs_sch", "root", "dbpassword", "3306")
                        '        'Dim ct = dbConnect.Count("wcs_msg_host")
                        '        'Console.WriteLine(ct.ToString())
                    Else
                        Console.WriteLine("Port forwarding has failed.")
                    End If

                Catch e As SshException
                    Console.WriteLine("SSH client connection error: {0}", e.Message)
                Catch e As System.Net.Sockets.SocketException
                    Console.WriteLine("Socket connection error: {0}", e.Message)
                End Try

            End Using

        End Sub

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit dem ConnectSSH-Einstiegspunkt und der im Bericht gezeigten wiederholten Erstellung von ForwardedPortLocal. Reproduziere das Szenario über Nacht oder mit wiederholten Aufrufen und verfolge dann den Lebenszyklus der Portweiterleitung sowie das Verhalten bei der Freigabe; abgeschlossen ist die Arbeit, wenn wiederholte Verbindungen keine stetig zunehmende Speichernutzung mehr zeigen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
csharp
Bereich
networking
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
30/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.