TansactionScope Timeout creashed app
See original GitHub issueIt seems only happened on MySQL.
When TransactionScope has a same timeout value with DbContext’CommandTimeout and excute command long time, the app will occure a exception and crash(the exception cant be catched).
the code as follow will easy reproduce the scenario:
static void Main(string[] args)
{
try
{
using (var scope = new TransactionScope(TransactionScopeOption.Required, TimeSpan.FromSeconds(5)))
using (var dbContext = new ADbContext())
{
dbContext.Database.CommandTimeout = 5;
var addClassA = new ClassA() { guid = "testNew" };
dbContext.ClassA.Add(addClassA);
dbContext.SaveChanges();
scope.Complete();
}
}
catch (Exception)
{
}
}
Abp’s Uow useTransactionScope and DbContext with same timeout value, It will be same scenario like above, In fact that our production already crashed several times in past half month, because sometime there are many parallel request comes and block the database so caused some request time out, then app will crash.
Now, I’m using DbContextEfTransactionStrategy insteading of TransactionScopeEfTransactionStrategy for avoiding the problem.
But it cause another problem which is very strange(somtimes will init dbcontext failded, exception is “MySql.Data.MySqlClient.MySqlException: Unable to connect to any of the specified MySQL hosts.”), I’m tring to find out what caused that.
I want to know whether there are other solutions except using DbContextEfTransactionStrategy. Appreciate any helps.
Issue Analytics
- State:
- Created 6 years ago
- Comments:14 (7 by maintainers)
Top GitHub Comments
Fixed. Will be released in v2.0.
Thanks,it fixed.