sshnet / sshnet/SSH.NET

Invalid handle for simultaneous downloads.

Open
#1,731 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
4.4k
Forks
993
Avg merge
9d 21h
Merged PRs (30d)
1

Description

I’m using a single SftpClient to download multiple files simultaneously. On one of a servers, I get "Invalid handle" error from time to time.
SSH.NET version 2024.2.0, .Net 9.
In connection logs I only see this version: Remote version: SSH-2.0-2.0

			"HResult": -2146233088,
			"Message": "Invalid handle.",
			"Source": "Renci.SshNet",
			"StackTrace": "   at Renci.SshNet.Sftp.SftpSession.RequestClose(Byte[] handle)\r\n   at Renci.SshNet.SftpClient.InternalUploadFile(Stream input, String path, Flags flags, SftpUploadAsyncResult asyncResult, Action`1 uploadCallback)\r\n   at Renci.SshNet.SftpClient.<>c__DisplayClass56_0.<BeginUploadFile>b__0()\r\n--- End of stack trace from previous location ---\r\n   at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)\r\n--- End of stack trace from previous location ---\r\n
			"TargetSite": "Void RequestClose(Byte[])",
			"Type": "Renci.SshNet.Common.SshException"

   at Renci.SshNet.Sftp.SftpSession.RequestClose(Byte[] handle)
   at Renci.SshNet.SftpClient.InternalUploadFile(Stream input, String path, Flags flags, SftpUploadAsyncResult asyncResult, Action`1 uploadCallback)
   at Renci.SshNet.SftpClient.<>c__DisplayClass56_0.<BeginUploadFile>b__0()
--- End of stack trace from previous location ---
   at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with SftpClient.BeginUploadFile and InternalUploadFile, then follow the SftpSession.RequestClose call shown in the stack trace. Inspect how a single SftpClient handles simultaneous operations and try to reproduce the intermittent error against the reported server conditions. Done means identifying the cause and verifying a fix or regression coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.