DetectsDeadlocks.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of Hyperf.
  5. *
  6. * @link https://www.hyperf.io
  7. * @document https://hyperf.wiki
  8. * @contact group@hyperf.io
  9. * @license https://github.com/hyperf/hyperf/blob/master/LICENSE
  10. */
  11. namespace Hyperf\Database;
  12. use Exception;
  13. use Hyperf\Stringable\Str;
  14. trait DetectsDeadlocks
  15. {
  16. /**
  17. * Determine if the given exception was caused by a deadlock.
  18. */
  19. protected function causedByDeadlock(Exception $e): bool
  20. {
  21. $message = $e->getMessage();
  22. return Str::contains($message, [
  23. 'Deadlock found when trying to get lock',
  24. 'deadlock detected',
  25. 'The database file is locked',
  26. 'database is locked',
  27. 'database table is locked',
  28. 'A table in the database is locked',
  29. 'has been chosen as the deadlock victim',
  30. 'Lock wait timeout exceeded; try restarting transaction',
  31. 'WSREP detected deadlock/conflict and aborted the transaction. Try restarting the transaction',
  32. ]);
  33. }
  34. }