Skip to content

Commit 8593a5e

Browse files
authored
Update Ydb.php
1 parent 2bc21f3 commit 8593a5e

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/Ydb.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ class Ydb
8888
*/
8989
protected $discoveryInterval = 60;
9090

91+
protected $triedDiscovery = false;
92+
9193
/**
9294
* @param array $config
9395
* @param LoggerInterface|null $logger
@@ -162,16 +164,21 @@ public function meta(): array
162164
*/
163165
public function discover()
164166
{
165-
$endpoints = $this->discovery()->listEndpoints();
166-
if (!empty($endpoints))
167-
{
168-
$this->cluster()->sync((array)$endpoints);
169-
$clusterEndpoints = array_map(function($e){
170-
return $e["address"].":".$e["port"];
167+
if ($this->triedDiscovery) return;
168+
$this->triedDiscovery = true;
169+
try {
170+
$endpoints = $this->discovery()->listEndpoints();
171+
if (!empty($endpoints)) {
172+
$this->cluster()->sync((array)$endpoints);
173+
$clusterEndpoints = array_map(function ($e) {
174+
return $e["address"] . ":" . $e["port"];
171175
}, (array)$endpoints);
172-
if(!array_search($this->endpoint, $clusterEndpoints)){
173-
$this->endpoint = $clusterEndpoints[array_rand($clusterEndpoints)];
176+
if (!array_search($this->endpoint, $clusterEndpoints)) {
177+
$this->endpoint = $clusterEndpoints[array_rand($clusterEndpoints)];
178+
}
174179
}
180+
} finally {
181+
$this->triedDiscovery = false;
175182
}
176183
}
177184

0 commit comments

Comments
 (0)