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

Why does parallel stream with lambda in static initializer cause a deadlock?

I found a bug report of a very similar case (JDK-8143380) which was closed as “Not an Issue” by Stuart Marks: This is a class initialization deadlock. The test program’s main thread executes the class static initializer, which sets the initialization in-progress flag for the class; this flag remains set until the static initializer completes. … Read more

Re-entrant locks in C#

No, not as long as you are locking on the same object. The recursive code effectively already has the lock and so can continue unhindered. lock(object) {…} is shorthand for using the Monitor class. As Marc points out, Monitor allows re-entrancy, so repeated attempts to lock on an object on which the current thread already … Read more

An async/await example that causes a deadlock

Take a look at this example, Stephen has a clear answer for you: So this is what happens, starting with the top-level method (Button1_Click for UI / MyController.Get for ASP.NET): The top-level method calls GetJsonAsync (within the UI/ASP.NET context). GetJsonAsync starts the REST request by calling HttpClient.GetStringAsync (still within the context). GetStringAsync returns an uncompleted … Read more