[SFTP] Race Condition during Rekeying: "Message type 93 is not valid" or Connection Drop
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 42/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- csharp
- Ambito
- networking
Direzione di ricerca
Inizia con Session.WaitOnHandle, Channel.SendData e SftpSession.RequestWrite, quindi traccia i percorsi sincrono e asincrono di UploadFile durante il rekeying. Riproduci il problema con un RekeyLimit del server di 500M 0 e un upload di grandi dimensioni ad alto throughput. Il lavoro è completato quando l’upload rimane connesso e termina senza gli errori Message type 93 o Client not connected.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Description
We are encountering critical connection failures during SFTP uploads under high network throughput. The issue appears to be a race condition during the SSH Rekeying phase.
When the server triggers a Key Rotation (due to RekeyLimit), the client fails to pause the data stream immediately. Consequently, the client sends a SSH_MSG_CHANNEL_DATA packet while the server has entered the Key Exchange state and expects SSH_MSG_KEXINIT, leading to a protocol violation.
Exceptions & Stack Traces
We observe two different exceptions depending on the server software/configuration:
Variant 1: Protocol Violation (Server sends Disconnect message)
Renci.SshNet.Common.SshConnectionException: Message type 93 is not valid.
at Renci.SshNet.Session.WaitOnHandle(WaitHandle waitHandle, TimeSpan timeout)
at Renci.SshNet.Session.WaitOnHandle(WaitHandle waitHandle)
at Renci.SshNet.Channels.Channel.SendData(Byte[] data)
at Renci.SshNet.Channels.Channel.SendMessage(Message message)
at Renci.SshNet.Channels.Channel.SendData(Byte[] buffer, Int32 offset, Int32 size)
at Renci.SshNet.Sftp.SftpSession.RequestWrite(Byte[] handle, UInt64 serverOffset, Byte[] data, Int32 offset, Int32 length, Action`1 writeStatusCallback)
Variant 2: Connection Drop (Server resets TCP connection)
Renci.SshNet.Common.SshConnectionException: Client not connected.
at Renci.SshNet.Common.AsyncResult.EndInvoke()
at Renci.SshNet.SftpClient.EndUploadFile(IAsyncResult asyncResult)
at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- End of stack trace from previous location ---
at FtpUtils.FtpUtils.SftpTransferFileAsync(...)
Steps to Reproduce
Configure an SFTP server with a low RekeyLimit (e.g., RekeyLimit 500M 0).
Establish a high-speed connection (e.g., > 500 Mbps).
Upload a file significantly larger than the limit.
Result: Connection crashes exactly when the limit is reached.
Analysis
The library seems unable to handle the state transition to KeyExchange fast enough when the outgoing socket buffer is saturated with file data. Confirmed Workaround: The issue is resolved only by setting RekeyLimit none on the server side, which confirms the issue is isolated to the rekeying phase.
Additional Info
- Reproducible on the latest revision 2025.1.0 as well as older versions.
- Reproducible with both synchronous UploadFile and asynchronous UploadFileAsync / BeginUploadFile implementations.
Question
Is there any client-side configuration or internal buffer setting that could mitigate this race condition without changing the server config? Or any other trick. Thanks!
- Lingua principale
- C#
- Stelle
- 4.4k
- Fork
- 994
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi 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à 5/5 Più di una settimana Idoneità per principianti 45/100
-
ShellStream.Expect over-discards on undecodable bytes, driving ArrayBuffer.ActiveLength negativeAperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 52/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
-
Using SshClient on Linux under Wine throws System.Security.Cryptography.CryptographicExceptionAperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
Tutte le issue di sshnet/SSH.NET
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
lay295/TwitchDownloader#1675 ·
-
copilot documentation
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
space-wizards/RobustToolbox#7119 ·
I maintainer di solito rispondono entro 1 giorno
-
Bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 4 giorni
-
.NET Bug Waiting for: Product Owner
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
getsentry/sentry-dotnet#5666 · 2 commenti ·
I maintainer di solito rispondono entro 2 giorni