PHP, MySQL, and “Lock wait timeout exceeded”

A client I have has a PHP script that is cron’d to run at certain times during the day. All of sudden, the script stopped working. I first checked to see if any of the code had changed: it had not. Because it creates dynamic PDF’s on-the-fly”, I made sure the proper directories existed, and they had the correct permissions. Check and check.

I then took a look at my handy debugging output I use for such an occasion, and found the following error:

Error 0: Lock wait timeout exceeded; try restarting transaction

The culprit: a script used to compile a PDF dynamically from files stored in the database “hung” because of an error within the compiling portion of the script. Because it never completed, the MySQL lock never completed, as it timed out. Therefore, if I understand it correctly, the lock was never released, so future updates wouldn’t work.

The fix: I first fixed what was hanging the PDF compiler (in this case switching from `gs` to `pdftk`). I then restarted MySQL, and all is well.

Comments

comments

Posted in Linux Tagged with: ,