SapientGuardian / mysql-connector-net-netstandard

ADO.NET driver for MySQL targeted against netstandard 1.3
GNU General Public License v2.0
46 stars 15 forks source link

Transaction not rollbacked on Dispose #30

Closed ghost closed 7 years ago

ghost commented 7 years ago

When used with EntityFrameworkCore, transactions are not rollbacked on Dispose.

In transaction.cs, the Dispose(bool) method is rollbacking the transaction. But as the method is not marked as override, it only hides the Dispose(bool) method from DbTransaction and will only be called if the type of the variable is MysqlTransaction.

DbTransaction dbTransaction = new MysqlTransaction();
dbTransaction.Dispose(true); // calls DbTransaction.Dispose(bool);

MysqlTransaction mysqlTransaction = new MysqlTransaction();
mysqlTransaction.Dispose(true); // calls MysqlTransaction.Dispose(bool);

Therefore, when the RelationalTransaction from EntityFrameworkCore calls the Dispose method on it's _dbTransaction, it won't call the MysqlTransaction.Dispose(bool) method but the one from DbTransaction (that does nothing).

transaction.cs

internal void Dispose(bool disposing)
    {
      if (disposing)
      {
        if ((conn != null && conn.State == ConnectionState.Open || conn.SoftClosed) && open)
          Rollback();
      }
    }

Fix: transaction.cs

protected override void Dispose(bool disposing)
    {
      if (disposing)
      {
        if ((conn != null && conn.State == ConnectionState.Open || conn.SoftClosed) && open)
          Rollback();
      }
    }
IntelOrca commented 7 years ago

@cfinance Why don't you submit a PR instead?

SapientGuardian commented 7 years ago

Thanks for the report, I'll get this changed in the next couple days if nobody beats me to it with a PR.