question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TansactionScope Timeout creashed app

See original GitHub issue

It 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:closed
  • Created 6 years ago
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
hikalkancommented, Apr 15, 2017

Fixed. Will be released in v2.0.

0reactions
ShiningRushcommented, Apr 15, 2017

Thanks,it fixed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TransactionScope timeout weirdness with ...
This typically happens when one logical transaction spans two (or more) database connections. Of course, in your case there is (apparently) only ...
Read more >
TransactionScope always Aborts with error "The ...
The TransactionScope class uses a default timeout (TransactionManager.DefaultTimeout, which has a default value of 1 minute). One solution is to put this in ......
Read more >
Troubleshooting Transactional Issues with TransactionScope
Timeout -related Errors - Ensuring you have appropriate timeouts set can be a challenge if you start running into errors, as the defaults...
Read more >
Implementing an Implicit Transaction using ...
The TransactionScope class provides a simple way to mark a block of code as participating in a transaction, without requiring you to ...
Read more >
TransactionScope Has a Default Timeout
The TransactionScope class uses a default timeout (TransactionManager.DefaultTimeout, which has a default value of 1 minute). When the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found