Skip to content

Commit

Permalink
Fixed potential bug, added comments (#302)
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkWanderer authored May 3, 2023
1 parent 961c83b commit a635e8e
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions ClickHouse.Client/ADO/ClickHouseConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,25 +193,34 @@ public virtual Feature SupportedFeatures

private void ResetHttpClientFactory()
{
if (httpClientFactory is IDisposable disposable)
// If current httpClientFactory is owned by this connection, dispose of it
if (httpClientFactory is IDisposable d && disposables.Contains(d))
{
disposable.Dispose();
disposables.Remove(disposable);
d.Dispose();
disposables.Remove(d);
}

// If we have a HttpClient provided, use it
if (providedHttpClient != null)
{
httpClientFactory = new CannedHttpClientFactory(providedHttpClient);
}

// If we have a provided client factory, use that
else if (providedHttpClientFactory != null)
{
httpClientFactory = providedHttpClientFactory;
}

// If sessions are enabled, always use single connection
else if (!string.IsNullOrEmpty(session))
{
var factory = new SingleConnectionHttpClientFactory() { Timeout = timeout };
disposables.Add(factory);
httpClientFactory = factory;
}

// Default case - use default connection pool
else
{
httpClientFactory = new DefaultPoolHttpClientFactory() { Timeout = timeout };
Expand Down

0 comments on commit a635e8e

Please sign in to comment.