sshnet / sshnet/SSH.NET

ForwardedPortLocal occasionally leads to CLOSE_WAIT connection

Aperta
#974 0 commenti 0 reazioni 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

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

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 riproducendo lo stato intermittente CLOSE_WAIT con ForwardedPortLocal, TcpClient e la sequenza del blocco finally mostrata nel report, concentrandoti su port.Stop(), sshClient.Disconnect() e tcpClient.Close(). Confronta il comportamento osservato della connessione lato Linux e di x11vnc nei diversi ordini di disconnessione; il lavoro è completo quando viene identificato l’ordine rilevante del ciclo di vita o la condizione di errore e il tunnel rilascia la connessione senza richiedere la terminazione manuale di x11vnc.

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.