Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

timeout in nested transactionscope

Reviewing some code that contains a bunch indirectly nested transactionscopes. I would like to know the way timeouts are handled in nested transactionscopes. Example code

void RootMethod()
{   
   //default timeout is 60 seconds 
   using(TransactionScope scope = new TransactionScope())
   {
      /* Perform transactional work here */
      SomeMethod();
      scope.Complete();
   }
}

void SomeMethod()
{   
   //set timeout to 30 seconds
   TimeSpan timeout = TimeSpan.FromSeconds(30);
   using(TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, timeout))
   {
      /* Perform transactional work here */
      scope.Complete();
   }
}

MSDN States - In a nested TransactionScope hierarchy, the timeout is the union of all timeouts. In effect, the smallest timeout of all scopes in the hierarchy, takes precedence.

The first statement says union of all timeouts but the second statment says its the smallest of all scopes. Am I right in understanding that the above code with a nested scope has a default timeout of 30 seconds and not 90?

like image 238
user529265 Avatar asked Jun 17 '26 05:06

user529265


1 Answers

It certainly won't be 90 seconds; that is the sum, not the union. The union of "now until 30 seconds" and "not until 60 seconds" is simply "now until 60 seconds". It should be pretty simple to verify, of course, by deliberately blocking yourself. I suspect it means "intersection of all timeouts", in which case it is the 30 seconds that matters; because: only the outermost transaction has the power to commit - but any transaction in a hive can doom the entire transaction (a rollback at any level rolls back the entire outermost transaction)

like image 156
Marc Gravell Avatar answered Jun 20 '26 00:06

Marc Gravell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!