Skip to content

Commit

Permalink
fix: swoft-cloud/swoft/issues/1303 rpc ext data key is error
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Jun 16, 2020
1 parent 0700226 commit 15bad43
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
4 changes: 1 addition & 3 deletions src/rpc-client/src/Concern/ServiceTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ private function sendAndRecv(Connection $connection, string $data, string $messa
if (!$connection->send($data)) {
if ($reconnect) {
$message = sprintf($message, $connection->getErrCode(), $connection->getErrMsg());
$connection->release();
throw new RpcClientException($message);
}

Expand All @@ -129,10 +128,9 @@ private function sendAndRecv(Connection $connection, string $data, string $messa

$result = $connection->recv();
if ($result === false || empty($result)) {
//Reconnected or receive date timeout
// Has been reconnected OR receive date timeout
if ($reconnect || $connection->getErrCode() === SOCKET_ETIMEDOUT) {
$message = sprintf($message, $connection->getErrCode(), $connection->getErrMsg());
$connection->release();
throw new RpcClientException($message);
}

Expand Down
10 changes: 5 additions & 5 deletions src/rpc-client/src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,17 @@ public function recv()
/**
* @return int
*/
public function getErrCode()
public function getErrCode(): int
{
return $this->connection->errCode;
return (int)$this->connection->errCode;
}

/**
* @return string
*/
public function getErrMsg()
public function getErrMsg(): string
{
return $this->connection->errMsg;
return (string)$this->connection->errMsg;
}

/**
Expand All @@ -177,7 +177,7 @@ private function getHostPort(): array
throw new RpcClientException(sprintf('Provider(%s) return format is error!', JsonHelper::encode($list)));
}

$randKey = array_rand($list, 1);
$randKey = array_rand($list, 1);
$hostPort = explode(':', $list[$randKey]);

if (count($hostPort) < 2) {
Expand Down
8 changes: 4 additions & 4 deletions src/rpc-client/src/Extender.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ class Extender implements ExtenderInterface
public function getExt(): array
{
return [
context()->get('traceid', ''),
context()->get('spanid', ''),
context()->get('parentid', ''),
context()->get('extra', null),
'traceid' => context()->get('traceid', ''),
'spanid' => context()->get('spanid', ''),
'parentid' => context()->get('parentid', ''),
'extra' => context()->get('extra', null),
];
}
}
2 changes: 1 addition & 1 deletion src/rpc-client/src/ReferenceRegister.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static function getPool(string $className): string
public static function getVersion(string $className): string
{
$version = self::$references[$className]['version'] ?? '';
if ($version == '') {
if ($version === '') {
throw new RpcClientException(sprintf('`@Reference` version(%s) is not exist!', $className));
}

Expand Down

0 comments on commit 15bad43

Please sign in to comment.