DetectsDeadlocks.php 891B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace Illuminate\Database;
  3. use Exception;
  4. use Illuminate\Support\Str;
  5. trait DetectsDeadlocks
  6. {
  7. /**
  8. * Determine if the given exception was caused by a deadlock.
  9. *
  10. * @param \Exception $e
  11. * @return bool
  12. */
  13. protected function causedByDeadlock(Exception $e)
  14. {
  15. $message = $e->getMessage();
  16. return Str::contains($message, [
  17. 'Deadlock found when trying to get lock',
  18. 'deadlock detected',
  19. 'The database file is locked',
  20. 'database is locked',
  21. 'database table is locked',
  22. 'A table in the database is locked',
  23. 'has been chosen as the deadlock victim',
  24. 'Lock wait timeout exceeded; try restarting transaction',
  25. 'WSREP detected deadlock/conflict and aborted the transaction. Try restarting the transaction',
  26. ]);
  27. }
  28. }