8000 Reject connection attempt when no AAAA and A records are resolved by WyriHaximus · Pull Request #251 · reactphp/socket · GitHub
[go: up one dir, main page]

Skip to content

Reject connection attempt when no AAAA and A records are resolved #251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Reject connection attempt when no AAAA and A records are resolved
  • Loading branch information
WyriHaximus committed Sep 22, 2020
commit 367f88d3be8c89688f7b3c8dffb8b315c0913f12
18 changes: 17 additions & 1 deletion src/HappyEyeBallsConnectionBuilder.php
8000
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ public function connect()

$that->mixIpsIntoConnectQueue($ips);

if ($that->hasBeenResolved() && $that->ipsCount === 0) {
$reject(new \RuntimeException($that->error()));
}

// start next connection attempt if not already awaiting next
if ($that->nextAttemptTimer === null && $that->connectQueue) {
$that->check($resolve, $reject);
Expand Down Expand Up @@ -123,7 +127,19 @@ public function connect()
public function resolve($type, $reject)
{
$that = $this;
return $that->resolver->resolveAll($that->host, $type)->then(null, function (\Exception $e) use ($type, $reject, $that) {
return $that->resolver->resolveAll($that->host, $type)->then(function ($ips) use ($that, $type) {
if (\count($ips) === 0) {
if ($type === Message::TYPE_A) {
$that->lastError4 = 'no records found';
$that->lastErrorFamily = 4;
} else {
$that->lastError6 = 'no records found';
$that->lastErrorFamily = 6;
}
}

return $ips;
}, function (\Exception $e) use ($type, $reject, $that) {
unset($that->resolverPromises[$type]);
$that->resolved[$type] = true;

Expand Down
15 changes: 15 additions & 0 deletions tests/HappyEyeBallsConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,21 @@ public function testCancelDuringTcpConnectionCancelsTcpConnectionIfGivenIp()
$this->loop->run();
}

public function testConnectionFailsWhenNoAAAOrARecordsAreResolved()
{
$this->resolver->expects($this->exactly(2))->method('resolveAll')->withConsecutive(
array('google.com', Message::TYPE_AAAA),
array('google.com', Message::TYPE_A)
)->willReturnOnConsecutiveCalls(
$this->returnValue(Promise\resolve(array())),
$this->returnValue(Promise\resolve(array()))
);
$this->tcp->expects($this->never())->method('connect');

$this->setExpectedException('RuntimeException', 'Connection to scheme://google.com:80/?hostname=google.com failed during DNS lookup: no records found');
Block\await($this->connector->connect('scheme://google.com:80/?hostname=google.com'), $this->loop, 3);
}

/**
* @internal
*/
Expand Down
0