我的代码中有许多交易,在其中一项交易执行时发生错误,但不会触发提交或回滚,则数据库会被锁定,并且任何后续尝试访问数据库的操作都会导致以下结果:
production.ERROR: PDOException: SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction in /home/forge/default/vendor/laravel/framework/src/Illuminate/Database/Connection.php:390
在控制器中:
DB::beginTransaction();
try {
//Code that uses exec() to process some images. <-- If code breaks here, then the above error appears on subsequent requests.
//Code that accesses the database
}
catch(\Exception $e){
DB::rollback();
throw $e;
}
DB::commit();
所以即使使用 php artisan migrate:refresh 或者 php artisan migrate:reset 命令也无法正常工作。我该如何解决这个问题?
tearDown()
方法,在那里我没有调用parent::tearDown()
。基本上,如果您不调用parent::tearDown()
,则事务仍然打开,并且回滚/断开连接从未发生过。 - alexkbparent::tearDown()
的调用,这让我调试了24个小时。感谢@Stoutie!! - bilogic\Exceptio
错误地输入成了\Exception
。 - undefined