From 5e34cd146cc12fc8c2c88eefce0a860ac7ae5285 Mon Sep 17 00:00:00 2001 From: halaei Date: Sat, 15 Oct 2016 19:45:01 +0330 Subject: [PATCH] dont rollback to savepoints on deadlock --- src/Illuminate/Database/Connection.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Illuminate/Database/Connection.php b/src/Illuminate/Database/Connection.php index 6ad94ef93595..48550563bfd3 100755 --- a/src/Illuminate/Database/Connection.php +++ b/src/Illuminate/Database/Connection.php @@ -576,6 +576,14 @@ public function transaction(Closure $callback, $attempts = 1) // up in the database. Then we'll re-throw the exception so it can // be handled how the developer sees fit for their applications. catch (Exception $e) { + // On deadlock, if this is a nested transaction, we cannot retry. + // the outer most transaction is rolled back by the server + // so we shouldn't rollback to save points. + if ($this->causedByDeadlock($e) && $this->transactions > 1) { + --$this->transactions; + throw $e; + } + $this->rollBack(); if ($this->causedByDeadlock($e) && $a < $attempts) {