sshnet / sshnet/SSH.NET

ForwardedPortLocal occasionally leads to CLOSE_WAIT connection

Offen
#974 0 Kommentare 0 Reaktionen 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

I'm using ssh.net (previously plink) in order to establish a secure tunnel between a Linux machine running sshd and my client Windows server.
The tunnel is required to redirect VNC traffic from\to a not exposed VNC server (x11vnc bound to localhost:5900) in the Linux server to\from my Windows server where a VNC client connects to the ssh.net tunnel.

I randomly end up in half-open connections in the Linux server, the connection goes into CLOSE_WAIT forever and the x11vnc stays running and I have to manually kill the x11vnc process to release the CLOSE_WAIT server connection.
I would like to know how I can prevent it and get the disconnection fully acknowledged.

This is an schema of the code:

try
{
....
    var sshClient = new SshClient(sshConnectionInfo);
    sshClient.ErrorOccurred += SshError;
    sshClient.Connect();       
    port = new ForwardedPortLocal("127.0.0.1", 0, "127.0.0.1", 5900);
    port.Exception += PortException;
    sshClient.AddForwardedPort(port);
    port.Start();
    shell = sshClient.CreateShellStream(string.Empty, 0, 0, 0, 0, 0); // shell is required for other purposes
    shell.ErrorOccurred += ShellError;
....
    tcpClient = new TcpClient();
    tcpClient.Connect(port.BoundHost, (int)port.BoundPort);
    // At this point I'm able to get the stream out of the local connection to Read & Write Remote Frame Buffer                   
....                
    tcpClient.Close();
    tcpClient.Dispose();                
}
catch (Exception e)
{
    Console.WriteLine(e.Message);
}
finally
{
    port.Exception -= PortException;
    sshClient.ErrorOccurred -= SshError;
    sshClient.RemoveForwardedPort(port);                
    port.Stop();
    port.Dispose();    
    shell.ErrorOccurred -= ShellError;
    shell.Close();                
    sshClient.Disconnect();
}   

Any idea how to overcome this issue?
Is the order of executing port.Stop(), sshClient.Disconnect() and tcpClient.Close() important?

=========================================
ssh.net version: 2020.0.2
target framework: .NET 6.0
client OS: Win Server 2019
server OS: Embedded Linux
sshd version: OpenSSH 5.2p1, OpenSSL 0.97i

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 damit, den intermittierenden Zustand CLOSE_WAIT mit ForwardedPortLocal, TcpClient und der im Bericht gezeigten finally-Block-Sequenz zu reproduzieren, wobei der Schwerpunkt auf port.Stop(), sshClient.Disconnect() und tcpClient.Close() liegt. Vergleiche das beobachtete Linux-seitige Verbindungs- und x11vnc-Verhalten bei verschiedenen Reihenfolgen der Trennung; als abgeschlossen gilt die Aufgabe, wenn die relevante Reihenfolge im Lebenszyklus oder die Fehlerbedingung identifiziert ist und der Tunnel die Verbindung freigibt, ohne dass x11vnc manuell beendet werden muss.

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.