sftp - 为什么 BizTalk 2016 会杀死自定义管道组件线程?
问题描述
我有一个 BizTalk 自定义管道组件,它写入一个 SFTP 文件(使用 SSH.net),由 SFTP(WinSCP)接收位置触发。
重试中的代码偶尔(大约一半时间)既没有达到“成功”,也没有达到日志捕获块,并且管道内没有进一步的处理。我认为这意味着线程已被破坏。
我稍后添加了重试代码以使其尝试几次,但是随着线程被破坏,我并不总是成功或 3 次失败。
什么可能导致 BizTalk 2016 中出现这种行为?
public void Archive(byte[] content,
string archivePath,
string userName,
string password,
string serverAddress,
string sshHostKeyFingerprint)
{
Retry(3, () =>
{
try
{
using (var sftpClient = new SftpClient(serverAddress, userName, password))
{
if (!string.IsNullOrWhiteSpace(sshHostKeyFingerprint))
{
sshHostKeyFingerprint = sshHostKeyFingerprint.Split(' ').Last();
sftpClient.HostKeyReceived += delegate (object sender, HostKeyEventArgs e)
{
if (e.FingerPrint.SequenceEqual(ConvertFingerprintToByteArray(sshHostKeyFingerprint)))
e.CanTrust = true;
else
e.CanTrust = false;
};
}
sftpClient.Connect();
sftpClient.WriteAllBytes(archivePath, content);
sftpClient.Disconnect();
LogInfo($"Success");
}
}
catch (Exception exception)
{
// show the bad path for "No such file" errors
throw new InvalidOperationException($"Failed to create file '{archivePath}'", exception);
}
});
}
private void Retry(int maxAttempts, Action action)
{
int attempt = 1;
while (attempt <= maxAttempts)
{
try
{
action();
break; // success
}
catch (Exception exception)
{
LogWarning($"Attempt {attempt} Error: {exception.ToString()}");
if (attempt == maxAttempts)
throw; // final attempt exception propagated
}
finally
{
attempt++;
}
}
}
解决方案
推荐阅读
- javascript - CSS在圆圈外点击会导致事件
- apache - 在 Fedora 29 Live USB 上安装 Drupal
- javascript - 自动发布回asp.net后如何重新加载脚本?
- tkinter - Tkinter,框架内小部件内的小部件
- swift - 如何在 Swift 4 中仅圆角 NSButton 的一侧?
- scheme - 将列表的第二个元素移到前面的递归方法是什么?[球拍]
- c# - Regex.Matches 使用前瞻没有得到任何匹配
- html - 如何在忍者窗体中添加图标
- javascript - 使用 Node.js 从 firebase 获取特定的键值对
- c# - 从 Nunit 测试结果生成报告