ConnectionInfo.SendTimeout — configurable socket send timeout to prevent indefinite hangs on TCP zero-window stalls
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 70/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Tranquilla
- Stack tecnologico
- csharp
- Ambito
- networking
Direzione di ricerca
Inizia da ConnectionInfo.cs per esaminare la convalida del timeout esistente, quindi ispeziona la configurazione del socket sia in Connect() sia in ConnectAsync() in Session.cs. Aggiungi il comportamento configurabile di send-timeout descritto nell’issue, mantenendo il valore predefinito infinito, e verifica che un invio bloccato vada in timeout mentre le connessioni esistenti mantengono il loro comportamento.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Problem
When uploading files over SFTP to a slow or unresponsive server, Session.SendPacket() can hang indefinitely with no way to recover.
The root cause is in SocketAbstraction.Send():
var bytesSent = socket.Send(data, offset + totalBytesSent, totalBytesToSend - totalBytesSent, SocketFlags.None);
socket.Send() is a blocking call and Socket.SendTimeout is never set, so it defaults to 0 (infinite). When the server's TCP receive window drops to zero (the server is alive but not consuming data), the OS
holds the call open indefinitely — no exception, no return. The standard TCP dead-peer timeout (several minutes) only applies when the server is completely unreachable, not in the zero-window scenario.
This is distinct from the channel-level window wait in Channel.cs, which already has a 30-second timeout via ConnectionInfo.Timeout. That protection only covers the SSH protocol layer; it never gets a chance
to fire because execution is stuck in socket.Send() first.
OperationTimeout (on SftpClient) similarly cannot help — it guards the wait for an SFTP protocol response after a packet has been sent, not the send itself.
Proposed fix
Add SendTimeout to ConnectionInfo (default Timeout.InfiniteTimeSpan to preserve existing behaviour) and apply it to the socket immediately after connection:
// ConnectionInfo.cs
private TimeSpan _sendTimeout = System.Threading.Timeout.InfiniteTimeSpan;
public TimeSpan SendTimeout
{
get => _sendTimeout;
set
{
value.EnsureValidTimeout(nameof(SendTimeout));
_sendTimeout = value;
}
}
// Session.cs — both Connect() and ConnectAsync() paths
_socket = _serviceFactory.CreateConnector(ConnectionInfo, _socketFactory)
.Connect(ConnectionInfo);
_socket.SendTimeout = ConnectionInfo.SendTimeout.AsTimeout();
When SendTimeout elapses, socket.Send() throws SocketException with SocketError.TimedOut, which propagates out of SendPacket() and terminates the session normally.
Notes
- Default is infinite — no behaviour change for existing users
- The timeout is a stall detector, not a total-transfer budget: it resets on every successful send call, so large files over slow-but-healthy connections are not affected
- Applies to all SSH traffic (not just SFTP), which is correct — a stalled send on any packet type means the session is broken
- Lingua principale
- C#
- Stelle
- 4.4k
- Fork
- 993
- Merge medio
- 9g 21h
- PR unite (30g)
- 1
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di sshnet/SSH.NET
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
-
Using SshClient on Linux under Wine throws System.Security.Cryptography.CryptographicException Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 67/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 55/100
Tutte le issue di sshnet/SSH.NET
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
nightscout/nocturne#1379 ·
-
release-notes in .NET 11 RC2 Apertapriority-0
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
StackExchange/StackExchange.Redis#3249 ·
-
[Feat] 조합 영역 구분선 개선 Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100