mirror of
https://github.com/danog/dns.git
synced 2024-11-26 20:14:51 +01:00
Prevent UDP sockets from leaking and close sockets on timeouts
This commit is contained in:
parent
4dbc6b1038
commit
36ef1a6959
@ -218,6 +218,14 @@ final class BasicResolver implements Resolver {
|
|||||||
$response = yield $socket->ask($question, $this->config->getTimeout());
|
$response = yield $socket->ask($question, $this->config->getTimeout());
|
||||||
$this->assertAcceptableResponse($response);
|
$this->assertAcceptableResponse($response);
|
||||||
|
|
||||||
|
// UDP sockets are never reused, they're not in the $this->sockets map
|
||||||
|
if ($protocol === "udp") {
|
||||||
|
// Defer call, because it interferes with the unreference() call in Internal\Socket otherwise
|
||||||
|
Loop::defer(function () use ($socket) {
|
||||||
|
$socket->close();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if ($response->isTruncated()) {
|
if ($response->isTruncated()) {
|
||||||
if ($protocol !== "tcp") {
|
if ($protocol !== "tcp") {
|
||||||
// Retry with TCP, don't count attempt
|
// Retry with TCP, don't count attempt
|
||||||
@ -258,6 +266,12 @@ final class BasicResolver implements Resolver {
|
|||||||
return new Record($data, $type, $ttls[$type]);
|
return new Record($data, $type, $ttls[$type]);
|
||||||
}, $result[$type]);
|
}, $result[$type]);
|
||||||
} catch (TimeoutException $e) {
|
} catch (TimeoutException $e) {
|
||||||
|
// Defer call, because it might interfere with the unreference() call in Internal\Socket otherwise
|
||||||
|
Loop::defer(function () use ($socket, $uri) {
|
||||||
|
unset($this->sockets[$uri]);
|
||||||
|
$socket->close();
|
||||||
|
});
|
||||||
|
|
||||||
$i = ++$attempt % \count($nameservers);
|
$i = ++$attempt % \count($nameservers);
|
||||||
$socket = yield $this->getSocket($protocol . "://" . $nameservers[$i]);
|
$socket = yield $this->getSocket($protocol . "://" . $nameservers[$i]);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user