Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNOW-914532: Use async for session pool finalizer #790

Merged
merged 2 commits into from
Oct 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion Snowflake.Data/Core/Session/SessionPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ sealed class SessionPoolSingleton : IDisposable
}
~SessionPoolSingleton()
{
ClearAllPools();
// Use async for the finalizer due to possible deadlock
// when waiting for the CloseResponse task while closing the session
ClearAllPoolsAsync();
}

public void Dispose()
Expand Down Expand Up @@ -203,6 +205,16 @@ internal void ClearAllPools()
}
}

internal async void ClearAllPoolsAsync()
{
s_logger.Debug("SessionPool::ClearAllPoolsAsync");
foreach (SFSession session in _sessionPool)
{
await session.CloseAsync(CancellationToken.None).ConfigureAwait(false);
}
_sessionPool.Clear();
}

public void SetMaxPoolSize(int size)
{
_maxPoolSize = size;
Expand Down
Loading