SFTPClient hangs forever in Windows- and Linux-based Azure App Service
オープン
まだ誰も着手していません。
- 主要言語
- C#
- スター
- 4.4k
- フォーク
- 993
- 平均マージ
- 9日 21時間
- マージ済み PR(30日)
- 1
説明
We use an ASP.NET Core 3.1 Background Service to watch and import files from an Sftp Server.
We encountered two issues:
ListDirectoryAsynchangs forever (SSH.NET 2016.1.0)Connecthangs 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.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
Issue に示されている再現用の BackgroundWorker から始め、リンク先の 1945 行付近にある Session.cs を調べ、Connect と ListDirectoryAsync のパスに焦点を当てます。Azure App Service のハングまたは利用できない SFTP サーバーを再現し、影響を受ける操作が無期限にハングせず、設定されたタイムアウトを遵守することを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- csharp
- 領域
- networking
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100