Reset transaction level to zero, when reconnent to mysql server. (#1565)

This commit is contained in:
李铭昕 2020-04-15 18:59:49 +08:00 committed by GitHub
parent 825f4ffef5
commit 112e27157c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 2 deletions

View File

@ -2,7 +2,8 @@
## Fixed
- [#1563](https://github.com/hyperf/hyperf/pull/1563) Fixed crontab's `onOneServer` option not resetting mutex on shutdown
- [#1563](https://github.com/hyperf/hyperf/pull/1563) Fixed crontab's `onOneServer` option not resetting mutex on shutdown.
- [#1565](https://github.com/hyperf/hyperf/pull/1565) Reset transaction level to zero, when reconnent to mysql server.
# v1.1.25 - 2020-04-09

View File

@ -58,6 +58,10 @@ abstract class AbstractConnection extends Connection implements ConnectionInterf
public function retry(\Throwable $throwable, $name, $arguments)
{
if ($this->transactionLevel() > 0) {
throw $throwable;
}
if ($this->causedByLostConnection($throwable)) {
try {
$this->reconnect();

View File

@ -78,7 +78,7 @@ class MySQLConnection extends AbstractConnection
$this->connection = $connection;
$this->lastUseTime = microtime(true);
$this->transactions = 0;
return true;
}

View File

@ -93,6 +93,7 @@ class PDOConnection extends AbstractConnection
$this->connection = $pdo;
$this->lastUseTime = microtime(true);
$this->transactions = 0;
return true;
}

View File

@ -115,4 +115,17 @@ class PDODriverTest extends AbstractTestCase
$this->assertSame('Hyperf', $res['name']);
}
public function testTransactionLevelWhenReconnect()
{
$container = $this->getContainer();
$factory = $container->get(PoolFactory::class);
$pool = $factory->getPool('default');
$connection = $pool->get();
$this->assertSame(0, $connection->transactionLevel());
$connection->beginTransaction();
$this->assertSame(1, $connection->transactionLevel());
$connection->reconnect();
$this->assertSame(0, $connection->transactionLevel());
}
}