GeniusesOfSymfony / WebSocketBundle

:part_alternation_mark: Websocket server for Symfony applications (powered by Ratchet), includes a Autobahn.JS based JavaScript client
MIT License
610 stars 139 forks source link

General error: 2006 MySQL server has gone away. #299

Closed renatogcarvalho closed 4 years ago

renatogcarvalho commented 6 years ago

Hello folks,

Although I have enabled the PDO Periodic Pings as per mentioned on #197, I'm still getting this error from time to time:

An exception occurred while executing 'SET @@time_zone= :userTimeZone' with params ["US\/Pacific"]:

SQLSTATE[HY000]: General error: 2006 MySQL server has gone away. [Err: 0]

The only solution I found to circumvent this issue was rebooting the Websocket daemon once a day. On a side note, I'm currently using Supervisor to restart the service in case an exception occur, etc.

Any suggestions?

Thank you in advance.

Renato.

sercul commented 6 years ago

+1 I have same problem, in logs looks that periodic works correctly but when i try to login, database timeout

09:39:46 NOTICE [websocket] Successfully ping sql server (~34 ms) [] [] 09:40:06 NOTICE [websocket] Successfully ping sql server (~37 ms) [] [] 09:40:26 NOTICE [websocket] Successfully ping sql server (~43 ms) [] [] 09:40:46 NOTICE [websocket] Successfully ping sql server (~40 ms) [] [] 09:41:06 NOTICE [websocket] Successfully ping sql server (~37 ms) [] [] 09:41:26 NOTICE [websocket] Successfully ping sql server (~41 ms) [] [] 09:41:28 ERROR [websocket] Connection error occurred Warning: Error while sending QUERY packet. PID=30536 in /home/dev.symfony/libs/composer_vendor/doct rine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php line 105 ["connection_id" => 1779,"session_id" => "15150784505ac481a8b7f84850567664"] [] 09:41:28 ERROR [websocket] Connection error occurred Warning: Error while sending QUERY packet. PID=30536 in /home/dev.symfony/libs/composer_vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php line 105 ["connection_id" => 1779,"session_id" => "15150784505ac481a8b7f84850567664"] [] 09:41:28 DEBUG [websocket] Matched route "user_notification" ["user_id" => "5"] [] 09:41:31 ERROR [websocket] Connection error occurred SQLSTATE[HY000]: General error: 2006 MySQL server has gone away in /home/dev.symfony/libs/composer_vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php line 107 ["connection_id" => 1785,"session_id" => "16248249025ac481ab0005e375244600"] [] 09:41:31 ERROR [websocket] Connection error occurred SQLSTATE[HY000]: General error: 2006 MySQL server has gone away in /home/dev.symfony/libs/composer_vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php line 107 ["connection_id" => 1785,"session_id" => "16248249025ac481ab0005e375244600"] []

jbogunia commented 6 years ago

Hi, I have same problem :( Did You find any other solution than rebooting Websocket Daemon?

sercul commented 6 years ago

@jbogunia @renatogcarvalho For my situation i solved this this way, you can check my answer on stackoverflow https://stackoverflow.com/questions/49791176/symfony4-gos-websocket-error-mysql-server-has-gone-away

jbogunia commented 6 years ago

@sercul
I use peroidical ping like it is described in docs:

 try {
    $startTime = microtime(true);
    $this->entityManager->getConnection()->ping();
    $endTime = microtime(true);
    $this->logger->notice(sprintf('Successfully ping sql server by Doctrine (~%s ms)', round(($endTime - $startTime) * 100000), 2));
    } catch (\PDOException $e) {
        $this->logger->emergency('Sql server for Doctrine is gone, and unable to reconnect');
        throw $e;
    }

But it still doesn't works :(

sercul commented 6 years ago

@jbogunia I made a bit another

/**

  • Ping database server to keep the connection between websocket and lamp alive. / public function tick() { if (null === $this->pdo) { $this->logger->warning('Unable to ping sql server, service pdo is unavailable'); return; } //if connection is persistent we don't need to ping if (true === $this->pdo->getAttribute(\PDO::ATTR_PERSISTENT)) { return; } try { $startTime = microtime(true); $this->pdo->query('SELECT 1'); $endTime = microtime(true); $this->logger->notice(sprintf('Successfully ping sql server (~%s ms)', round(($endTime - $startTime) 100000), 2)); } catch (\PDOException $e) { $this->logger->emergency('Sql server is gone, and unable to reconnect'); throw $e; } }
jbogunia commented 6 years ago

OK, I found that I used wrong service in config in gos_web_socket section

periodic:
    - '@gos_web_socket.pdo.periodic_ping'

Now I changed to my custom peridoic ping service

periodic:
    - '@conversations.doctrine.periodic_ping'

And it working as it should ;)