Skip to content
This repository was archived by the owner on Jan 24, 2024. It is now read-only.

Commit 632488c

Browse files
authoredNov 3, 2021
Map mysqlnd Packets out of order error as ConnectionException (#83)
1 parent b5eb675 commit 632488c

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed
 

‎src/Driver/MySQL/MySQLDriver.php

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ protected function mapException(\Throwable $exception, string $query): Statement
6767
strpos($message, 'server has gone away') !== false
6868
|| strpos($message, 'broken pipe') !== false
6969
|| strpos($message, 'connection') !== false
70+
|| strpos($message, 'packets out of order') !== false
7071
|| ((int)$exception->getCode() > 2000 && (int)$exception->getCode() < 2100)
7172
) {
7273
return new StatementException\ConnectionException($exception, $query);

‎tests/Database/Driver/MySQL/ExceptionsTest.php

+22
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,33 @@
1111

1212
namespace Spiral\Database\Tests\Driver\MySQL;
1313

14+
use Spiral\Database\Exception\StatementException\ConnectionException;
15+
1416
/**
1517
* @group driver
1618
* @group driver-mysql
1719
*/
1820
class ExceptionsTest extends \Spiral\Database\Tests\ExceptionsTest
1921
{
2022
public const DRIVER = 'mysql';
23+
24+
public function testPacketsOutOfOrderConsideredAsConnectionExceptionFromPHP74(): void
25+
{
26+
if (PHP_VERSION_ID < 70400) {
27+
$this->markTestSkipped('Expecting PHP version >=7.4. Skipped due to ' . PHP_VERSION);
28+
}
29+
30+
// Prepare connection to generate "Packets out of order. Expected 1 received 0. Packet size=145"
31+
// at the next query response
32+
$this->database->query("SET SESSION wait_timeout=1")->fetch();
33+
sleep(1);
34+
35+
try {
36+
$result = $this->database->query('SELECT version() AS version')->fetchAll();
37+
$this->assertNotEmpty($result[0]['version'] ?? '', 'Expected result from second query');
38+
} catch (\RuntimeException $e) {
39+
$this->assertInstanceOf(ConnectionException::class, $e);
40+
return;
41+
}
42+
}
2143
}

0 commit comments

Comments
 (0)
This repository has been archived.