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) {