Skip to content

Commit

Permalink
SNOW-957736: Fix SnowflakeDbConnection.Dispose behaviour (#807)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-pbulawa authored Nov 9, 2023
1 parent 7f73791 commit 22d32dd
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions Snowflake.Data/Client/SnowflakeDbConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class SnowflakeDbConnection : DbConnection

internal int _connectionTimeout;

private bool disposed = false;
private bool _disposed = false;

private static Mutex _arraybindingMutex = new Mutex();

Expand Down Expand Up @@ -361,21 +361,30 @@ protected override DbCommand CreateDbCommand()

protected override void Dispose(bool disposing)
{
if (disposed)
return;

try
{
this.Close();
}
catch (Exception ex)
if (!_disposed)
{
// Prevent an exception from being thrown when disposing of this object
logger.Error("Unable to close connection", ex);
if (disposing)
{
try
{
Close();
}
catch (Exception ex)
{
// Prevent an exception from being thrown when disposing of this object
logger.Error("Unable to close connection", ex);
}
}
else
{
SfSession?.close();
SfSession = null;
_connectionState = ConnectionState.Closed;
}

_disposed = true;
}

disposed = true;

base.Dispose(disposing);
}

Expand Down

0 comments on commit 22d32dd

Please sign in to comment.