How to fix deadlocks with tests?

Skip to first unread message

Joshua Gardner

Oct 27, 2023, 12:21:29 PM10/27/23
I'm experiencing deadlocks in my production application occasionally. I'm
using MySQL. Some of these deadlocks are due to insufficient indexing,
and I'd like to fix this with some test-driven development.

How can I write tests that exercise the application concurrently, and
could be used to replicate the deadlocks and then fix them? I use
pytest-django and I use MySQL in my tests; there's a lot of raw SQL and
even some views and stored procedures (😱) in this application and some
of those may be culprits too of course.

I suppose my main question is "how to test bugs that occur due to


Chetan Ganji

Oct 27, 2023, 2:01:57 PM10/27/23
This problem seems to be unique. There might not be a standard solution.

You can replicate the prod environment to local and profile it using django silk.
If you can somehow manage to reproduce the bug and find the timestamp when it happened; 
you can find out the sql queries that were running around that timestamp. 
You might be able to find out the root cause of the problem and fix it.

I am not 100% sure if it will help. But it is worth a try. 
I hope it helps you.


Chetan Ganji

You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit
Reply all
Reply to author
0 new messages