sshnet / sshnet/SSH.NET

When SftpClient is disconnected during SftpClient .DownloadFile

Open
#981 0 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

Hi! together!

I've tried to download some files by SftpClient. Sometimes the program got freeze for some reason.
It's what I've tried to debug to see what was happening.

client.DownloadFile(sFilePath, fileStream, offset =>
{
    try
    {
        if (offset > 4389170) // I assume that the connection is disconnected while the file is being downloaded.
            client.Disconnect();
    }
    catch (Exception ex)
    {
    }
});

I've tried to make SftpClient disconnected while the file is being downloaded.
It seems I success reproduce the problem that I'm dealing with. (Actually I'm not 100% sure..)
It's doing nothing when It's disconnected. It is maybe because nothing come in on the callback function.

When if it turns out it's a bug, how about add some code inside of SftpClient.InternalDownloadFile while clause

if (IsConnected == false)
   throw new SshConnectionException("Connection has been disconnected.");

PS. It's my first time to post Issues on github. If there are some mistakes, please let me know.

UPDATE

I've checked it's stuck in a deadlock in SftpFileReader.Read() function when the connection get disconnected while file is being downloaded. Please someone help me and I want to discuss how to solve this problem with all of you.

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 by reproducing the disconnect during SftpClient.DownloadFile, then inspect SftpClient.InternalDownloadFile and the SftpFileReader.Read() deadlock identified in the issue. Trace what happens when the connection closes while the download callback is active. Done means the download no longer hangs and the disconnected state is handled with observable failure behavior.

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
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.