Join 34,000+ subscribers and receive articles from our blog about software quality, testing, QA and security.
 

mySQL DeadlockException error


#1

Hello,
We are getting this error in our testrail logs:

12:06:31 [DeadlockException] Deadlock found when trying to get lock; try restarting transaction

Details:
File: /var/www/html/testrail/sys/helpers/ex.php
Line: 25
Status Code: 500
Host: build.pdt
Uri: /testrail/index.php?/api/v2/add_result_for_case/1696/1161216 (POST)

Browser: Java/1.8.0_40
PHP: 5.3.3
Server: Linux 2.6.32-573.22.1.el6.x86_64 #1 SMP Wed Mar 23 03:35:39 UTC 2016 x86_64

Trace:
at ex::raise (ex.php:25)
at ex::raise (mysql.php:167)
at Database_mysql_driver->_throw_last_error (mysql.php:106)
at Database_mysql_driver->execute (database.php:925)
at Database_library->query (database.php:956)
at Database_library->insert (test.php:977)
at Test_model->_sync_assocs (test.php:939)
at Test_model->_insert_change (test.php:834)
at Test_model->_insert_change_all (test.php:807)
at Test_model->_trx_insert_change (callback.php:70)
at callback::runv (database.php:1235)
at Database_library->_transaction_exec (database.php:1221)
at Database_library->_transaction_run (database.php:1178)
at Database_library->transaction_run (test.php:743)
at Test_model->insert_change (v2.php:3021)
at V2_controller->_add_result (v2.php:2964)
at V2_controller->add_result_for_case (controller.php:257)
at Controller->_invoke_web_call (controller.php:168)
at Controller->_invoke_web (controller.php:120)
at Controller->_invoke (gizmo.php:107)
at require_once (index.php:106) +413ms
12:06:31 Database error code: 1213 (at Database_mysql_driver->_throw_last_error) +412ms

Do you know why this error might occur?
Thanks,
Cynthia


#2

http://www.softwareprojects.com/resources/programming/t-mysql-innodb-deadlocks-and-duplicate-key-errors-12-1970.html

See the section on the 1213 deadlock error.

https://dev.mysql.com/doc/refman/5.5/en/innodb-deadlocks.html


#3

Hi Cynthia,

Thanks for your posting. A deadlock often times indicates a performance issue on the database side (when you try to process more transactions than the database can handle). As you are using the API and try to add test results, I would recommend switching to the bulk API versions and add multiple test results in one step and this can significantly reduce the database load. The equivalent bulk version for add_result_for_case would be add_results_for_cases:

http://docs.gurock.com/testrail-api2/reference-results#add_results_for_cases

Cheers,
Tobias