'The session is not open' in ListDirectoryAsync
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 4.4k
- Forks
- 993
- Avg merge
- 9d 21h
- Merged PRs (30d)
- 1
Description
On rare occasions, I see 'The session is not open' in ListDirectoryAsync.
The last time I saw it, it was for a server where multiple instances of sftpClient might get created simultaneously with the same username/password, but working with different folders.
SSH.NET 2025.1.0 .Net 9.
My code looks like this:
try
{
await sftpClient.ConnectAsync(cancellationToken);
await sftpClient.ChangeDirectoryAsync(path, cancellationToken);
var asyncList = sftpClient.ListDirectoryAsync(path, cancellationToken);
}
finally
{
if (sftpClient.IsConnected)
sftpClient.Disconnect();
}
"Type": "System.InvalidOperationException",
"HResult": -2146233079,
"Message": "The session is not open.",
"Source": "Renci.SshNet",
"StackTrace": " at Renci.SshNet.Sftp.SftpSession.SendRequest(SftpRequest request)\r\n at Renci.SshNet.Sftp.SftpSession.GetCanonicalPathAsync(String path, CancellationToken cancellationToken)\r\n at Renci.SshNet.SftpClient.ListDirectoryAsync(String path, CancellationToken cancellationToken)+MoveNext()\r\n at Renci.SshNet.SftpClient.ListDirectoryAsync(String path, CancellationToken cancellationToken)+System.Threading.Tasks.Sources.IValueTaskSource.GetResult()",
"TargetSite": "Void SendRequest(Renci.SshNet.Sftp.Requests.SftpRequest)"
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at SftpClient.ListDirectoryAsync and trace the reported path through SftpSession.GetCanonicalPathAsync and SftpSession.SendRequest. Try to reproduce the failure with multiple SftpClient instances using the same credentials while listing different folders, and inspect session lifetime around ConnectAsync, ListDirectoryAsync, and Disconnect. Done means the rare 'The session is not open' failure is understood and covered by a reliable test or a documented limitation.
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