Skip to content

Commit

Permalink
Make transaction scope timeout the same as command timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
sebgod committed Feb 10, 2025
1 parent f4b5d51 commit 12a7151
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/grate.core/Migration/GrateMigrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,17 @@ public async Task Migrate()
// Start the transaction, if configured
if (runInTransaction)
{
scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled);
// use command timeout as the max timeout and transaction scope timeout, if greater than current MaxTimeout
var maxTimeout = TransactionManager.MaxTimeout;
var transactionTimeout = config.CommandTimeout > 0
? new [] {maxTimeout, TimeSpan.FromSeconds(config.CommandTimeout) }.Max();
: maxTimeout;

if (transactionTimeout > maxTimeout)
{
TransactionManager.MaxTimeout = transactionTimeout;
}
scope = new TransactionScope(TransactionScopeOption.Required, transactionTimeout, TransactionScopeAsyncFlowOption.Enabled);
}

bool exceptionOccured = false;
Expand Down

0 comments on commit 12a7151

Please sign in to comment.