Skip to content

Commit cf51269

Browse files
committed
Check whether active transaction still exists before rollback
If transaction has become broken during commit its rollback leads to new exception which will overwrite the original one. Check for active transaction should work because on exception within driver.CommitTransaction() active transaction is set to NULL.
1 parent 19baf81 commit cf51269

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

Orm/Xtensive.Orm/Orm/Upgrade/UpgradingDomainBuilder.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,13 @@ private void CompleteUpgradeTransaction()
172172
driver.CommitTransaction(null, connection);
173173
}
174174
catch {
175-
driver.RollbackTransaction(null, connection);
175+
// If transaction has become broken during commit its rollback leads to new exception
176+
// which will overwrite the original one.
177+
// Check for active transaction should work because on exception within
178+
// driver.Commit it is set to NULL.
179+
if (connection.ActiveTransaction != null) {
180+
driver.RollbackTransaction(null, connection);
181+
}
176182
throw;
177183
}
178184
}
@@ -190,7 +196,13 @@ private async ValueTask CompleteUpgradeTransactionAsync(CancellationToken token)
190196
await driver.CommitTransactionAsync(null, connection, token);
191197
}
192198
catch {
193-
await driver.RollbackTransactionAsync(null, connection, token);
199+
// If transaction has become broken during commit its rollback leads to new exception
200+
// which will overwrite the original one.
201+
// Check for active transaction should work because on exception within
202+
// driver.Commit it is set to NULL.
203+
if (connection.ActiveTransaction != null) {
204+
await driver.RollbackTransactionAsync(null, connection, token);
205+
}
194206
throw;
195207
}
196208
}

0 commit comments

Comments
 (0)