Working around MySQL error “Deadlock found when trying to get lock; try restarting transaction”

If you are using InnoDB or any row-level transactional RDBMS, then it is possible that any write transaction can cause a deadlock, even in perfectly normal situations. Larger tables, larger writes, and long transaction blocks will often increase the likelihood of deadlocks occurring. In your situation, it’s probably a combination of these. The only way … Read more

What does “lock | communication buffer resources” mean?

I would interpret the message as a deadlock on some combination of Lock resources or Communication Buffer resources. “Lock resources” are ordinary object locks, and “Communication Buffer resources” are exchangeEvents used for combining results of parallel queries. These are described further in https://blogs.msdn.microsoft.com/bartd/2008/09/24/todays-annoyingly-unwieldy-term-intra-query-parallel-thread-deadlocks/ where the relevant paragraph is: An “exchangeEvent” resource indicates the presence of … Read more

Transaction deadlock for select query

My init understanding is that a Select query won’t lock a table, or won’t cause a deadlock This understanding is wrong. SELECT queries take shared locks on the rows they analyze. Shared locks may conflict exclusive locks from update/delete/insert statements. Two SELECT statements are not going to deadlock, but a SELECT can deadlock with an … Read more

Would you explain lock ordering?

In the simple case given, unlocking in the reverse order is not necessary to avoid a deadlock. However, as the code gets more complicated, unlocking in the reverse order helps you maintain proper lock ordering. Consider: A.lock(); B.lock(); Foo(); A.unlock(); Bar(); B.unlock(); If Bar() attempts to reacquire A, you’ve effectively broken your lock ordering. You’re … Read more

What are common reasons for deadlocks?

Update: This recent MSDN article, Tools And Techniques to Identify Concurrency Issues, might also be of interest Stephen Toub in the MSDN article Deadlock monitor states the following four conditions necessary for deadlocks to occur: A limited number of a particular resource. In the case of a monitor in C# (what you use when you … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)