Skip to content

Commit

Permalink
Update DiscoveredServer.cs (#206)
Browse files Browse the repository at this point in the history
Convert Cancelled exceptions to Timeouts on existence check, allow 10 seconds not 3 since some DB servers are slow...
  • Loading branch information
jas88 authored Aug 7, 2023
1 parent d80b25a commit 9f60827
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions FAnsiSql/Discovery/DiscoveredServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,23 @@ public DiscoveredDatabase ExpectDatabase(string database)
/// <param name="timeoutInMillis"></param>
/// <exception cref="TimeoutException"></exception>
/// <exception cref="AggregateException"></exception>
public void TestConnection(int timeoutInMillis = 3000)
public void TestConnection(int timeoutInMillis = 10000)
{
using var con = Helper.GetConnection(Builder);
using(var tokenSource = new CancellationTokenSource(timeoutInMillis))
using (var openTask = con.OpenAsync(tokenSource.Token))
{
try
{
openTask.Wait(tokenSource.Token);
openTask.Wait(timeoutInMillis, tokenSource.Token);
}
catch (OperationCanceledException e)
{
throw new TimeoutException(
string.Format(
FAnsiStrings
.DiscoveredServer_TestConnection_Could_not_connect_to_server___0___after_timeout_of__1__milliseconds_,
Name, timeoutInMillis), e);
}
catch (AggregateException e)
{
Expand Down

0 comments on commit 9f60827

Please sign in to comment.