sshnet / sshnet/SSH.NET

SSHClient: ForwardedPortLocal: memory issue

Aperta
#775 6 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
C#
Stelle
4.4k
Fork
993
Merge medio
9g 21h
PR unite (30g)
1

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia dal punto di ingresso ConnectSSH e dalla creazione ripetuta di ForwardedPortLocal mostrata nel report. Riproduci lo scenario durante la notte o con chiamate ripetute, quindi traccia il ciclo di vita del port forwarding e il comportamento di rilascio; il lavoro è completato quando le connessioni ripetute non mostrano più un uso della memoria in costante aumento.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
csharp
Ambito
networking
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
30/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.