private async Task ReconnectAsync(CancellationToken cancellationToken) {
var sessions = _sessions.Values.ToList();
if (sessions.Any()) {
try {
await WhenAllCancelOnFailure(sessions, (s, ct) => s.ReconnectAsync(ct), cancellationToken);
} catch (OperationCanceledException ex) when (!(ex is RHostDisconnectedException)) {
throw;
} catch (Exception ex) {
_console.Write(Resources.RSessionProvider_ConnectionFailed.FormatInvariant(ex.Message) + Environment.NewLine);
throw;
}
} else {
await TestBrokerConnectionWithRHost(_brokerProxy, cancellationToken);
}
}