Skip to content

Commit

Permalink
Fix bugs for Dispose to make it more robust.
Browse files Browse the repository at this point in the history
  • Loading branch information
ChTimTsubasa committed Apr 4, 2019
1 parent 4bb3eb4 commit 8f57667
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
16 changes: 15 additions & 1 deletion Snowflake.Data/Client/SnowflakeDbConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public SecureString Password
get; set;
}

public bool IsOpen()
{
return _connectionState == ConnectionState.Open;
}

public override string Database => _connectionState == ConnectionState.Open ? SfSession.database : string.Empty;

public override int ConnectionTimeout => this._connectionTimeout;
Expand Down Expand Up @@ -100,7 +105,16 @@ public override void Open()
{
logger.Debug("Open Connection.");
SetSession();
SfSession.Open();
try
{
SfSession.Open();
}
catch (Exception e)
{
// Otherwise when Dispose() is called, the close request would timeout.
_connectionState = ConnectionState.Closed;
throw e;
}
OnSessionEstablished();
}

Expand Down
8 changes: 6 additions & 2 deletions Snowflake.Data/Client/SnowflakeDbTransaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,12 @@ protected override void Dispose(bool disposing)
if (disposed)
return;

// Snowflake can handle a rollback for a rollback without any transaction
this.Rollback();
// Rollback the uncommitted transaction when the connection is open
if (connection != null && connection.IsOpen())
{
// When there is no uncommitted transaction, Snowflake would just ignore the rollback request;
this.Rollback();
}
disposed = true;

base.Dispose(disposing);
Expand Down

0 comments on commit 8f57667

Please sign in to comment.