Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở
#1,764 6 bình luận 0 reaction 0 người được giao Xem trên GitHub

@radekvermirovsky đang làm issue này rồi.

Từ ngày 12/8/2026.

  • #1823 của @radekvermirovsky — đang mở

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
42/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
csharp
Lĩnh vực
networking

Hướng nghiên cứu

Bắt đầu với Session.WaitOnHandle, Channel.SendData và SftpSession.RequestWrite, sau đó lần theo các đường dẫn UploadFile đồng bộ và bất đồng bộ trong quá trình rekeying. Tái hiện bằng RekeyLimit của máy chủ là 500M 0 và một lượt tải lên lớn với thông lượng cao. Được xem là hoàn tất khi kết nối tải lên vẫn được duy trì và quá trình tải lên hoàn tất mà không có lỗi Message type 93 hoặc Client not connected.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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!

Ngôn ngữ chính
C#
Star
4.4k
Fork
990
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của sshnet/SSH.NET

Tất cả issue của sshnet/SSH.NET

Issue tương tự

Thêm issue về C#

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.