Skip to content

Commit

Permalink
throw deadlock exception (#42129)
Browse files Browse the repository at this point in the history
  • Loading branch information
imanghafoori1 authored Apr 25, 2022
1 parent 704f275 commit 6b87641
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Illuminate/Database/Concerns/ManagesTransactions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Illuminate\Database\Concerns;

use Closure;
use Illuminate\Database\DeadlockException;
use RuntimeException;
use Throwable;

Expand Down Expand Up @@ -87,7 +88,11 @@ protected function handleTransactionException(Throwable $e, $currentAttempt, $ma
$this->getName(), $this->transactions
);

throw $e;
throw new DeadlockException(
$e->getMessage(),
$e->getCode(),
$e->getPrevious()
);
}

// If there was an exception we will rollback this transaction and then we
Expand Down Expand Up @@ -226,8 +231,7 @@ protected function handleCommitTransactionException(Throwable $e, $currentAttemp
{
$this->transactions = max(0, $this->transactions - 1);

if ($this->causedByConcurrencyError($e) &&
$currentAttempt < $maxAttempts) {
if ($this->causedByConcurrencyError($e) && $currentAttempt < $maxAttempts) {
return;
}

Expand Down
10 changes: 10 additions & 0 deletions src/Illuminate/Database/DeadlockException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Illuminate\Database;

use PDOException;

class DeadlockException extends PDOException
{
//
}

0 comments on commit 6b87641

Please sign in to comment.