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?
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)