mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-01-18 21:32:27 +01:00
Make sure SSHClient Disconnect does not hang if a cancellationToken is passed
This commit is contained in:
parent
4d68b12080
commit
12264d8e74
@ -102,7 +102,7 @@ namespace BTCPayServer
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Task DisconnectAsync(this SshClient sshClient)
|
public static async Task DisconnectAsync(this SshClient sshClient, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
if (sshClient == null)
|
if (sshClient == null)
|
||||||
throw new ArgumentNullException(nameof(sshClient));
|
throw new ArgumentNullException(nameof(sshClient));
|
||||||
@ -121,7 +121,10 @@ namespace BTCPayServer
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
{ IsBackground = true }.Start();
|
{ IsBackground = true }.Start();
|
||||||
return tcs.Task;
|
using (cancellationToken.Register(() => tcs.TrySetCanceled()))
|
||||||
|
{
|
||||||
|
await tcs.Task;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ namespace BTCPayServer.HostedServices
|
|||||||
{
|
{
|
||||||
using (var connection = await _options.SSHSettings.ConnectAsync(_cancellationTokenSource.Token))
|
using (var connection = await _options.SSHSettings.ConnectAsync(_cancellationTokenSource.Token))
|
||||||
{
|
{
|
||||||
await connection.DisconnectAsync();
|
await connection.DisconnectAsync(_cancellationTokenSource.Token);
|
||||||
Logs.Configuration.LogInformation($"SSH connection succeeded");
|
Logs.Configuration.LogInformation($"SSH connection succeeded");
|
||||||
canUseSSH = true;
|
canUseSSH = true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user