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-957736: Fix SnowflakeDbConnection.Dispose behaviour #807

Merged
merged 1 commit into from
Nov 9, 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
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();
sfc-gh-dstempniak marked this conversation as resolved.
Show resolved Hide resolved
SfSession = null;
_connectionState = ConnectionState.Closed;
}

_disposed = true;
}

disposed = true;

base.Dispose(disposing);
}

Expand Down
Loading