Skip to content
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

Non-existing domain with domain that resolves to IPv6 address #222

Closed
Rodeoclash opened this issue Jan 30, 2022 · 6 comments
Closed

Non-existing domain with domain that resolves to IPv6 address #222

Rodeoclash opened this issue Jan 30, 2022 · 6 comments

Comments

@Rodeoclash
Copy link

Rodeoclash commented Jan 30, 2022

A quick (likely stupid) question that I couldn't find an answer for in the repo or Elixir community forums Does Redix support IPV6?

I'm attempting to connect to a Redis instance on fly.io and while I seem to be able to resolve the address:

# ping vodon-redis.internal
PING vodon-redis.internal(fdaa:0:3924:a7b:ead:0:84e5:2 (fdaa:0:3924:a7b:ead:0:84e5:2)) 56 data bytes
64 bytes from fdaa:0:3924:a7b:ead:0:84e5:2 (fdaa:0:3924:a7b:ead:0:84e5:2): icmp_seq=1 ttl=62 time=39.4 ms
64 bytes from fdaa:0:3924:a7b:ead:0:84e5:2 (fdaa:0:3924:a7b:ead:0:84e5:2): icmp_seq=2 ttl=62 time=34.3 ms

and have connectivity to the Redis instance:

# telnet vodon-redis.internal 6379
Trying fdaa:0:3924:a7b:ead:0:84e5:2...
Connected to vodon-redis.internal.
Escape character is '^]'.
AUTH 5cX*******************
+OK

Things don't want to play nicely once I'm attempting to connect from within Elixir:

06:17:52.643 [error] Failed to connect to Redis (redis://vodon-redis.internal/1:6379): non-existing domain

My naïve assumption would be to configure the connection as follows:

Redix.start_link(
  host: "redis://vodon-redis.internal/1",
  socket_opts: [:inet6]
)

However I seem to be missing some nuance around passing the configuration to the underlying Erlang connection.

If I can get this resolved, happy to update your docs and also feed this back up to the Fly team to add to the page they have on configuring Redis 🙂

@whatyouhide
Copy link
Owner

Hey @Rodeoclash, thanks for the report.

I think we should support IPv6 out of the box. We are not doing anything in Redix to resolve addresses manually or anything.

I don't have an easy way right now to play with IPv6 DNS addresses. Can you try playing around with inet:resolve/5 and see if it shows any issues?

Alternatively, do you have a minimal reproducing case using Docker or a well-known accessible address that I can use to easily reproduce this locally on my machine?

Thanks! 💟

@whatyouhide whatyouhide changed the title IPv6 Support? Non-existing domain with domain that resolves to IPv6 address Jan 31, 2022
@Rodeoclash
Copy link
Author

Sounds good. I'll dig in the next couple of days and see if I can identify how we might resolve it.

If I can't get to the bottom of it I'll put together a test repo with docker-compose.yml which will at least give you a test harness 🙂

@whatyouhide
Copy link
Owner

@Rodeoclash that sounds great. Redix already has a docker-compose.yml file so if you prefer you can go and play with this in your Redix fork itself 🙃

@Rodeoclash
Copy link
Author

Hmm, I think I have a workaround of sorts but I'm not sure how correct it is. Firstly, I can resolve the domain:

:inet_res.resolve('vodon-redis.internal', :in, :aaaa)

{:ok,
 {:dns_rec, {:dns_header, 4, true, :query, false, false, true, false, false, 0},
  [{:dns_query, 'vodon-redis.internal', :aaaa, :in, false}],
  [
    {:dns_rr, 'vodon-redis.internal', :aaaa, :in, 0, 5,
     {64938, 0, 14628, 2683, 3757, 0, 34021, 2}, :undefined, [], false}
  ], [], []}}

However if I attempt to directly use the hostname with :gen_tcp then I get the same nxdomain error when I use Redix directly:

:gen_tcp.connect('vodon-redis.internal', 6379, [:binary, active: false])

{:error, :nxdomain}

Likewise, if I use the IPv6 address as a binary with it

:gen_tcp.connect('fdaa:0:3924:a7b:232f:54c4:a4a2:2', 6379, [:binary, active: false])

{:error, :nxdomain}

However, if I use the IPv6 tuple then the connection is established

:gen_tcp.connect({64938, 0, 14628, 2683, 3757, 0, 34021, 2}, 6379, [:binary, active: false])

{:ok, #Port<0.2111>}

So my work around could be to simply lookup the IPv6 address using :inet_res.resolve on boot and pass that to the connection string.

Either way, not a Redix issue but a :gen_tcp issue! I'll close the ticket 🙂

@whatyouhide
Copy link
Owner

@Rodeoclash that's a super interesting find though, thanks for taking the time to share it and report back! I'm egoistically glad it's not a Redix issue 😉

@Rodeoclash
Copy link
Author

For anyone else that finds this, my final configuration looked like this:

redix_connection: [
  name: :redix,
  host: "vodon-redis.internal",
  password: redis_password,
  port: 6379,
  socket_opts: [:inet6]
]

I couldn't use the URL parsing method but specify the options individually worked with aplomb.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants