Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

[SFTP] Race Condition during Rekeying: "Message type 93 is not valid" or Connection Drop

オープン
#1,764 コメント 6 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
42/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
csharp
領域
networking

調査の方向性

Session.WaitOnHandle、Channel.SendData、SftpSession.RequestWrite から始め、rekeying 中の同期および非同期の UploadFile パスを追跡します。サーバーの RekeyLimit を 500M 0 に設定し、高スループットで大容量のアップロードを行って再現します。アップロードの接続が維持され、Message type 93 または Client not connected エラーなしで完了すれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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!

主要言語
C#
スター
4.4k
フォーク
994
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

sshnet/SSH.NET のほかの issue

sshnet/SSH.NET の issue をすべて見る

似ている issue

C# の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。