Optimized code for closing amqp connection (#3219)

This commit is contained in:
李铭昕 2021-01-27 18:23:30 +08:00 committed by GitHub
parent 4790d69878
commit 3235820803
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -137,11 +137,13 @@ class Connection extends BaseConnection implements ConnectionInterface
public function close(): bool
{
try {
if ($this->connection->getIO() instanceof KeepaliveIO) {
$this->connection->getIO()->close();
}
if ($connection = $this->connection) {
if ($connection->getIO() instanceof KeepaliveIO) {
$connection->getIO()->close();
}
$this->connection->close();
$connection->close();
}
} catch (AMQPConnectionClosedException $exception) {
$this->getLogger()->warning((string) $exception);
} catch (\Throwable $exception) {