mirror of
https://github.com/danog/dns.git
synced 2024-11-30 04:29:06 +01:00
Set pending request before send
While unlikely, the same request ID could have been selected while waiting to send.
This commit is contained in:
parent
d26f9bb44f
commit
375bf3f63b
@ -48,7 +48,7 @@ abstract class Socket {
|
||||
/**
|
||||
* @param string $uri
|
||||
*
|
||||
* @return Promise<\Amp\Dns\Server>
|
||||
* @return Promise<self>
|
||||
*/
|
||||
abstract public static function connect(string $uri): Promise;
|
||||
|
||||
@ -88,6 +88,7 @@ abstract class Socket {
|
||||
return;
|
||||
}
|
||||
|
||||
\assert($message instanceof Message);
|
||||
$id = $message->getId();
|
||||
|
||||
// Ignore duplicate and invalid responses.
|
||||
@ -128,16 +129,6 @@ abstract class Socket {
|
||||
$id = \random_int(0, 0xffff);
|
||||
} while (isset($this->pending[$id]));
|
||||
|
||||
$message = $this->createMessage($question, $id);
|
||||
|
||||
try {
|
||||
yield $this->send($message);
|
||||
} catch (StreamException $exception) {
|
||||
$exception = new DnsException("Sending the request failed", 0, $exception);
|
||||
$this->error($exception);
|
||||
throw $exception;
|
||||
}
|
||||
|
||||
$deferred = new Deferred;
|
||||
$pending = new class {
|
||||
use Amp\Struct;
|
||||
@ -150,6 +141,16 @@ abstract class Socket {
|
||||
$pending->question = $question;
|
||||
$this->pending[$id] = $pending;
|
||||
|
||||
$message = $this->createMessage($question, $id);
|
||||
|
||||
try {
|
||||
yield $this->send($message);
|
||||
} catch (StreamException $exception) {
|
||||
$exception = new DnsException("Sending the request failed", 0, $exception);
|
||||
$this->error($exception);
|
||||
throw $exception;
|
||||
}
|
||||
|
||||
$this->input->reference();
|
||||
|
||||
if (!$this->receiving) {
|
||||
|
Loading…
Reference in New Issue
Block a user