Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why is django leaving locks behind in mysql?

I have a Django app that uses MySQL and the InnoDB engine for storage. For some reason, Django sometimes leaves locks in place, even after the query has completed. (I can see them with Innotop).

The only transaction-handling stuff that I do in my code is that I have django.db.transaction.commit_on_success specified for some of my save() methods where I am working with multi-table inheritance.

If I restart the Apache server, the locks go away.

Has anyone seen something like this? Could I have written in some anti-pattern that would cause this?

like image 958
Chris Curvey Avatar asked Jun 21 '10 17:06

Chris Curvey


1 Answers

The only time I've managed to accomplish this was by setting up "scheduled" tasks in Django that weren't related to requests/views. The default auto-commit transaction handling system only commits transactions when a request/response pair is completed and sent back to the end user, so creating kron-esque jobs that run without a request being sent bypasses that mechanism.

Otherwise it's generally pretty difficult to make it fail to release a lock. You're sure there aren't extremely long-running blocks of code (perhaps relying on an external service that's timing out or something of the sort) tying things up?

like image 155
Gabriel Hurley Avatar answered Nov 11 '22 02:11

Gabriel Hurley