Skip to content

Commit

Permalink
fix(GfuKiQDV): DataStoreException throws instead of ConnectionExcepti…
Browse files Browse the repository at this point in the history
…on when connection is lost during preparing sql statement
  • Loading branch information
misha-rollun committed Aug 9, 2024
1 parent a18e537 commit acbae6d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/DataStore/src/DataStore/ConnectionException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

/**
* Error establishing TCP (or any other, specific for datastore) connection
* Also can be thrown if the connection is lost during operation
*/
class ConnectionException extends DataStoreException
{
Expand Down
12 changes: 11 additions & 1 deletion src/DataStore/src/DataStore/LaminasDbExceptionDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,23 @@

namespace rollun\datastore\DataStore;

use Laminas\Db\Adapter\Exception\InvalidQueryException;
use Laminas\Db\Adapter\Exception\RuntimeException;
use Throwable;

class LaminasDbExceptionDetector
{
private const MYSQL_SERVER_HAS_GONE_AWAY = 'MySQL server has gone away';

public static function isConnectionException(Throwable $e): bool
{
// When connection is lost during preparing SQL in Laminas\Db\Adapter\Driver\Mysqli\Statement::prepare()
if ($e instanceof InvalidQueryException && $e->getPrevious()) {
if (str_starts_with($e->getPrevious()->getMessage(), self::MYSQL_SERVER_HAS_GONE_AWAY)) {
return true;
}
}

if (!$e instanceof RuntimeException) {
return false;
}
Expand All @@ -30,7 +40,7 @@ public static function isOperationTimedOutException(Throwable $e): bool
}
if (
// Exception message from a Mysqli driver: Laminas\Db\Adapter\Driver\Mysqli\Statement
str_starts_with($e->getMessage(), 'MySQL server has gone away')
str_starts_with($e->getMessage(), self::MYSQL_SERVER_HAS_GONE_AWAY)
) {
return true;
}
Expand Down

0 comments on commit acbae6d

Please sign in to comment.