sshnet / sshnet/SSH.NET

SFTPClient hangs forever in Windows- and Linux-based Azure App Service

Aperta
#736 0 commenti 4 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
C#
Stelle
4.4k
Fork
993
Merge medio
9g 21h
PR unite (30g)
1

Descrizione

We use an ASP.NET Core 3.1 Background Service to watch and import files from an Sftp Server.

We encountered two issues:

  • ListDirectoryAsync hangs forever (SSH.NET 2016.1.0)
  • Connect hangs forever (SSH.NET 2020.0.0-beta1)
    • After running it for about 2 days successfully)

I created a little repro application were calls to ListDirectoryAsync and Connect are involved.

public class BackgroundWorker : BackgroundService
{
    private readonly ILogger<BackgroundWorker> _logger;

    public BackgroundWorker(ILogger<BackgroundWorker> logger)
    {
        _logger = logger;
    }

    protected override async Task ExecuteAsync(CancellationToken stoppingToken)
    {
        do
        {
            var host = "";
            var username = "";
            var password = "";
            var uri = new Uri(host);
            var path = "FI/Sample";
            var parsedHost = uri.Host;

            _logger.LogInformation($"{DateTime.Now} - Creating new client ...");
            var parsedPort = uri.Port;
            var connectionInfo = new PasswordConnectionInfo(parsedHost, parsedPort, username, password)
            {
                Timeout = TimeSpan.FromSeconds(120),
            };

            var client = new SftpClient(connectionInfo);

            _logger.LogInformation($"{DateTime.Now} - Client created.");

            client.OperationTimeout = TimeSpan.FromMinutes(3);
            _logger.LogInformation($"{DateTime.Now} - Connecting ...");
            client.Connect();
            _logger.LogInformation($"{DateTime.Now} - Connected");

            var stopwatch = new Stopwatch();
            stopwatch.Start();
            _logger.LogInformation($"{DateTime.Now} - ListDirectoryAsync ...");
            var immutableArray = (await client.ListDirectoryAsync(path))
                .Where(x => x.IsRegularFile)
                .Select(x => new { x.Name, x.LastWriteTimeUtc })
                .ToImmutableArray();

            _logger.LogInformation($"{DateTime.Now} - Done({immutableArray.Length}) {stopwatch.ElapsedMilliseconds}ms");

            _logger.LogInformation($"{DateTime.Now} - Disposing ...");
            client.Dispose();
            connectionInfo.Dispose();
            _logger.LogInformation($"{DateTime.Now} - Disposed.");
            await Task.Delay(1000);

        } while (true);
    }
}

Further findings:

  • We could see that both Linux and Windows-based App Services hung at the same time. So it seems that the Sftp Server might have had an issue at that time. Nevertheless SSH.NET should handle this with a timeout.
  • We could also see that if we increase our polling interval hanging process were less frequent.

If you need more information, let me know.

Update:
Seems like https://github.com/sshnet/SSH.NET/blob/cefdc203d98cd890815e029bc759bc43ec5a9643/src/Renci.SshNet/Session.cs#L1945 is the problem.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con il BackgroundWorker di riproduzione mostrato nell’issue ed esamina Session.cs intorno alla riga collegata 1945, concentrandoti sui percorsi Connect e ListDirectoryAsync. Riproduci il blocco di Azure App Service o un server SFTP non disponibile, quindi verifica che l’operazione interessata rispetti il timeout configurato invece di rimanere bloccata indefinitamente.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
csharp
Ambito
networking
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.