Can't connect to local DNS name
rodrigowbazevedo opened this issue · 11 comments
I have a local DNS alias in my /etc/hosts
just named redis
wich points to my Redis server when I try to create the client with the Factory::createClient
using this DNS the React\Dns\Resolver\Resolver
search for it in this server 8.8.8.8 (Google's DNS Server) and can't resolve because it's local.
Hi @rodrigowbazevedo, are you sure you're running the latest versions? This should be supported as of #66. I've verified that this does indeed work locally.
I'm using version 2.1 I'll update it to 2.2 and test again, Thanks.
I updated my dependencies and I still get this error DNS Request did not return valid answer.
I'd like to look into this and reproduce this locally. Can you show the output of composer info
and your hosts
file?
This library essentially passes the hostname to react/socket, which passes it to react/dns. Can you see if https://github.com/reactphp/dns/blob/master/examples/01-one.php works for you?
The output of this script was IP for www.google.com: 216.58.202.100
I tried with localhost
and got this output IP for localhost: 127.0.0.1
I tried with redis
host and got React\Dns\RecordNotFoundException: DNS Request did not return valid answer.
My composer info
cboden/ratchet v0.4.1 PHP WebSocket library
clue/ami-react v0.4.0 Streaming, event-driven access to the Asterisk Manager Interface (AMI), built on top of ReactPHP
clue/redis-protocol v0.3.1 A streaming redis wire protocol parser and serializer implementation in PHP
clue/redis-react v2.2.0 Async Redis client implementation, built on top of ReactPHP
evenement/evenement v3.0.1 Événement is a very simple event dispatching library for PHP
guzzlehttp/psr7 1.4.2 PSR-7 message implementation that also provides common utility methods
justinrainbow/json-schema 1.6.1 A library to validate a json schema.
pimple/pimple v3.2.3 Pimple, a simple Dependency Injection Container
psr/container 1.0.0 Common Container Interface (PHP FIG PSR-11)
psr/http-message 1.0.1 Common interface for HTTP messages
ratchet/rfc6455 v0.2.3 RFC6455 WebSocket protocol handler
react/cache v0.4.2 Async, Promise-based cache interface for ReactPHP
react/dns v0.4.12 Async DNS resolver for ReactPHP
react/event-loop v0.4.3 Event loop abstraction layer that libraries can use for evented I/O.
react/promise v2.5.1 A lightweight implementation of CommonJS Promises/A for PHP
react/promise-timer v1.2.1 A trivial implementation of timeouts for Promises, built on top of ReactPHP.
react/socket v0.8.9 Async, streaming plaintext TCP/IP and secure TLS socket server and client connections for ReactPHP
react/stream v0.7.7 Event-driven readable and writable streams for non-blocking I/O in ReactPHP
seld/jsonlint 1.7.1 JSON Linter
symfony/http-foundation v4.0.4 Symfony HttpFoundation Component
symfony/polyfill-mbstring v1.7.0 Symfony polyfill for the Mbstring extension
symfony/routing v4.0.4 Symfony Routing Component
webmozart/assert 1.3.0 Assertions to validate method input/output with nice error messages.
webmozart/json 1.2.2 A robust JSON decoder/encoder with support for schema validation.
webmozart/path-util 2.3.0 A robust cross-platform utility for normalizing, comparing and modifying file paths.
zendframework/zend-config 3.1.0 provides a nested object property based user interface for accessing this configuration data within application...
zendframework/zend-stdlib 3.1.0
The react/dns package uses the same handling for localhost
as for any other hostname listed in the your hosts
file. I wonder if there may be an issue in your hosts
file, can you show (parts of) its contents?
I'm using it inside a docker container with docker-compose, in older versions of docker-compose when you create a link between containers he puts the hostname inside /etc/hosts
, but now I looked at it and he doesn't put the hostname inside /etc/hosts
anymore, but if I ping the hostname it works... I don't know how... The hostname works well using with PDO for exemple...
Interesting find. This sounds more like an issue with your environment and/or you may be affected by reactphp/socket#90. For now, you can explicitly pass your local DNS proxy address to the Connector
or explicitly pass custom host mappings to Docker with the --add-host redis:10.1.2.3
flag (or extra_hosts
with docker-compose).
See also https://docs.docker.com/engine/userguide/networking/default_network/dockerlinks/ and https://docs.docker.com/engine/userguide/networking/#embedded-dns-server for more details.
I hope this helps 👍
Perfect I think using the docker embedded DNS server will work.
This has been fixed via reactphp/socket#152 which has just been released https://github.com/reactphp/socket/releases/tag/v0.8.10 🎉 This means that this should now work out of the box if you update react/socket to v0.4.10.
Please report back if the problem persists 👍
Great to know I'll test it!