diff --git a/src/Appwrite/Network/Validator/DNS.php b/src/Appwrite/Network/Validator/DNS.php index 2dc3504a96..0021068fc9 100644 --- a/src/Appwrite/Network/Validator/DNS.php +++ b/src/Appwrite/Network/Validator/DNS.php @@ -2,7 +2,7 @@ namespace Appwrite\Network\Validator; -use Swoole\Coroutine\WaitGroup; +use Swoole\Coroutine\Channel; use Utopia\DNS\Message\Record; use Utopia\DNS\Validator\DNS as BaseDNS; @@ -32,34 +32,27 @@ class DNS extends BaseDNS */ public function isValid(mixed $value): bool { - $wg = new WaitGroup(); - $failedValidator = null; + $serverCount = \count($this->dnsServers); + $channel = new Channel($serverCount); foreach ($this->dnsServers as $dnsServer) { - $wg->add(); - - \go(function () use ($value, $dnsServer, $wg, &$failedValidator) { - try { - $validator = new BaseDNS($this->target, $this->type, $dnsServer); - $isValid = $validator->isValid($value); - - if (!$isValid) { - $failedValidator = $validator; - } - } finally { - $wg->done(); - } + \go(function () use ($value, $dnsServer, $channel) { + $validator = new BaseDNS($this->target, $this->type, $dnsServer); + $valid = $validator->isValid($value); + $channel->push(['valid' => $valid, 'validator' => $validator]); }); } - $wg->wait(); - - if (!\is_null($failedValidator)) { - $this->count = $failedValidator->count; - $this->value = $failedValidator->value; - $this->reason = $failedValidator->reason; - $this->records = $failedValidator->records; - return false; + for ($i = 0; $i < $serverCount; $i++) { + $result = $channel->pop(); + if (!$result['valid']) { + $failed = $result['validator']; + $this->count = $failed->count; + $this->value = $failed->value; + $this->reason = $failed->reason; + $this->records = $failed->records; + return false; + } } return true;