Here are some tips in my experience ...
If you are doing test development, isolate which combination of tests produces an error. Use any mechanism provided by your ecosystem to run tests selectively (example: @group only for testing methods and phpunit --group only )
Then reduce the wait time for the lock wait ( SET GLOBAL innodb_lock_wait_timeout = 10 ). This way you get quick feedback and don't spend your whole day waiting for tests. Mileage may vary. Adjust your specific conditions.
Thirdly, pay attention to open transactions, i.e. start without rolling back or fixing. It turned out to be just my problem. My attempt / catch did not wrap enough logic, and this was a mistake between the start of the transaction and the rollback from try-catch.
Fourth, consider placing all parts of a transaction in the same try-catch, which has several advantages in making sure that all parts are easily visible. Example:
try { DB::beginTransaction(); $this->someMethodThatMightThrow(); DB::commit(); } catch (Exception $e) { DB::rollBack(); throw $e; }
These are my two cents. Hope helpful to someone online.
Stoutie
source share