Rails

How To Fix Mysql::Error: Lock Wait Timeout Exceeded; Try Restarting Transaction Deadlocks In Your Rails Tests

Posted by Weston Ganger on December 06, 2016

If you are constantly recieving errors about Mysql::Error: Lock wait timeout exceeded you may have a dangling transaction.

To check your current active MySQL connection do:


mysql

mysql> show processlist;
----+------+-----------------+---------------+---------+-------+-------+------------------+
| Id | User | Host            | db            | Command | Time  | State | Info             |
+----+------+-----------------+---------------+---------+-------+-------+------------------+
|  1 | root | localhost:49172 | myapp         | Sleep   |   441 |       | NULL             |
|  2 | root | localhost       | myapp         | Query   |     0 | NULL  | show processlist |        |
|  3 | root | localhost       | myapp_test    | Sleep   | 63703 |       | NULL             |             |
+----+------+-----------------+---------------+---------+-------+-------+------------------+
3 rows in set (0.00 sec)

You can see here that process ID 3 for myapp_test has been dangling for a long time. We need to kill that process.


mysql> kill 3;


Related External Links:


Posted in Rails and Tagged with mysql testing 


Need help on your next project or application?

I specialize in Ruby-on-Rails, AngularJS, Javascript, Bootstrap, and Hybrid Mobile Apps with Cordova & Ionic.

Contact Me

Recommended Posts