Skip to content

Commit

Permalink
SNOW-914532: Use async for session pool finalizer (#790)
Browse files Browse the repository at this point in the history
### Description
Regarding issue 648

The PR fixes a hanging issue due to a [possible
deadlock](https://github.com/snowflakedb/snowflake-connector-net/blob/127343fb4f8a55597df3bf3f20e64e18975fcb62/Snowflake.Data/Core/RestRequester.cs#L54)
by using async instead when the finalizer tries to close all the
sessions in the pool

### Checklist
- [x] Code compiles correctly
- [x] Code is formatted according to [Coding
Conventions](../CodingConventions.md)
- [x] Created tests which fail without the change (if possible)
- [x] All tests passing (`dotnet test`)
- [x] Extended the README / documentation, if necessary
- [x] Provide JIRA issue id (if possible) or GitHub issue id in PR name
  • Loading branch information
sfc-gh-ext-simba-lf authored Oct 26, 2023
1 parent 64b638c commit 9237a3d
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion Snowflake.Data/Core/Session/SessionPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ internal SessionPool()

~SessionPool()
{
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 @@ -191,6 +193,16 @@ internal void ClearAllPools()
}
}

internal async void ClearAllPoolsAsync()
{
s_logger.Debug("SessionPool::ClearAllPoolsAsync");
foreach (SFSession session in _sessionPool)

Check failure on line 199 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Linux (net6.0, AWS)

The name '_sessionPool' does not exist in the current context

Check failure on line 199 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Linux (net6.0, AWS)

The name '_sessionPool' does not exist in the current context

Check failure on line 199 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Linux (net6.0, AZURE)

The name '_sessionPool' does not exist in the current context

Check failure on line 199 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Linux (net6.0, AZURE)

The name '_sessionPool' does not exist in the current context

Check failure on line 199 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Linux (net6.0, GCP)

The name '_sessionPool' does not exist in the current context

Check failure on line 199 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Linux (net6.0, GCP)

The name '_sessionPool' does not exist in the current context

Check failure on line 199 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on MAC (net6.0, AZURE)

The name '_sessionPool' does not exist in the current context

Check failure on line 199 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on MAC (net6.0, AZURE)

The name '_sessionPool' does not exist in the current context

Check failure on line 199 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on MAC (net6.0, AWS)

The name '_sessionPool' does not exist in the current context

Check failure on line 199 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on MAC (net6.0, AWS)

The name '_sessionPool' does not exist in the current context

Check failure on line 199 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on MAC (net6.0, GCP)

The name '_sessionPool' does not exist in the current context

Check failure on line 199 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on MAC (net6.0, GCP)

The name '_sessionPool' does not exist in the current context

Check failure on line 199 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, AWS)

The name '_sessionPool' does not exist in the current context

Check failure on line 199 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, AWS)

The name '_sessionPool' does not exist in the current context

Check failure on line 199 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, GCP)

The name '_sessionPool' does not exist in the current context

Check failure on line 199 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, GCP)

The name '_sessionPool' does not exist in the current context

Check failure on line 199 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net6.0, AWS)

The name '_sessionPool' does not exist in the current context

Check failure on line 199 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net6.0, AWS)

The name '_sessionPool' does not exist in the current context

Check failure on line 199 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, AWS)

The name '_sessionPool' does not exist in the current context

Check failure on line 199 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, AWS)

The name '_sessionPool' does not exist in the current context

Check failure on line 199 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, AZURE)

The name '_sessionPool' does not exist in the current context

Check failure on line 199 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, AZURE)

The name '_sessionPool' does not exist in the current context

Check failure on line 199 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, GCP)

The name '_sessionPool' does not exist in the current context

Check failure on line 199 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, GCP)

The name '_sessionPool' does not exist in the current context

Check failure on line 199 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net6.0, AZURE)

The name '_sessionPool' does not exist in the current context

Check failure on line 199 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net6.0, AZURE)

The name '_sessionPool' does not exist in the current context

Check failure on line 199 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, AZURE)

The name '_sessionPool' does not exist in the current context

Check failure on line 199 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, AZURE)

The name '_sessionPool' does not exist in the current context

Check failure on line 199 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net6.0, GCP)

The name '_sessionPool' does not exist in the current context

Check failure on line 199 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net6.0, GCP)

The name '_sessionPool' does not exist in the current context
{
await session.CloseAsync(CancellationToken.None).ConfigureAwait(false);
}
_sessionPool.Clear();

Check failure on line 203 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Linux (net6.0, AWS)

The name '_sessionPool' does not exist in the current context

Check failure on line 203 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Linux (net6.0, AWS)

The name '_sessionPool' does not exist in the current context

Check failure on line 203 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Linux (net6.0, AZURE)

The name '_sessionPool' does not exist in the current context

Check failure on line 203 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Linux (net6.0, AZURE)

The name '_sessionPool' does not exist in the current context

Check failure on line 203 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Linux (net6.0, GCP)

The name '_sessionPool' does not exist in the current context

Check failure on line 203 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Linux (net6.0, GCP)

The name '_sessionPool' does not exist in the current context

Check failure on line 203 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on MAC (net6.0, AZURE)

The name '_sessionPool' does not exist in the current context

Check failure on line 203 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on MAC (net6.0, AZURE)

The name '_sessionPool' does not exist in the current context

Check failure on line 203 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on MAC (net6.0, AWS)

The name '_sessionPool' does not exist in the current context

Check failure on line 203 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on MAC (net6.0, AWS)

The name '_sessionPool' does not exist in the current context

Check failure on line 203 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on MAC (net6.0, GCP)

The name '_sessionPool' does not exist in the current context

Check failure on line 203 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on MAC (net6.0, GCP)

The name '_sessionPool' does not exist in the current context

Check failure on line 203 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, AWS)

The name '_sessionPool' does not exist in the current context

Check failure on line 203 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, AWS)

The name '_sessionPool' does not exist in the current context

Check failure on line 203 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, GCP)

The name '_sessionPool' does not exist in the current context

Check failure on line 203 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, GCP)

The name '_sessionPool' does not exist in the current context

Check failure on line 203 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net6.0, AWS)

The name '_sessionPool' does not exist in the current context

Check failure on line 203 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net6.0, AWS)

The name '_sessionPool' does not exist in the current context

Check failure on line 203 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, AWS)

The name '_sessionPool' does not exist in the current context

Check failure on line 203 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, AWS)

The name '_sessionPool' does not exist in the current context

Check failure on line 203 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, AZURE)

The name '_sessionPool' does not exist in the current context

Check failure on line 203 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, AZURE)

The name '_sessionPool' does not exist in the current context

Check failure on line 203 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, GCP)

The name '_sessionPool' does not exist in the current context

Check failure on line 203 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net472, GCP)

The name '_sessionPool' does not exist in the current context

Check failure on line 203 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net6.0, AZURE)

The name '_sessionPool' does not exist in the current context

Check failure on line 203 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net6.0, AZURE)

The name '_sessionPool' does not exist in the current context

Check failure on line 203 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, AZURE)

The name '_sessionPool' does not exist in the current context

Check failure on line 203 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net471, AZURE)

The name '_sessionPool' does not exist in the current context

Check failure on line 203 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net6.0, GCP)

The name '_sessionPool' does not exist in the current context

Check failure on line 203 in Snowflake.Data/Core/Session/SessionPool.cs

View workflow job for this annotation

GitHub Actions / Tests on Windows (net6.0, GCP)

The name '_sessionPool' does not exist in the current context
}

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

0 comments on commit 9237a3d

Please sign in to comment.