Skip to content

Comments

Add IPv6 support for gRPC gun adapter#495

Merged
polvalente merged 8 commits intoelixir-grpc:masterfrom
num42:fix/ipv6_support_master
Feb 10, 2026
Merged

Add IPv6 support for gRPC gun adapter#495
polvalente merged 8 commits intoelixir-grpc:masterfrom
num42:fix/ipv6_support_master

Conversation

@KalleJoP
Copy link
Contributor

@KalleJoP KalleJoP commented Feb 9, 2026

Summary

Improves IPv6 support for gRPC client connections by (1) falling back to AAAA DNS lookups when no A records exist, and (2) passing IP addresses to Gun as tuples instead of strings.

Why

IPv6 connections were failing with the Gun adapter for two reasons:

  1. Missing AAAA lookup — For dns:// targets, only A (IPv4) records were queried. Hosts that expose only IPv6 or that we want to use over IPv6 had no resolved addresses, so the client never attempted an IPv6 connection.
  2. Host format for Gun — When an IPv6 address was used (e.g. from a manual config), it was passed to :gun.open/3 as a string. Gun expects IP addresses as inet:ip_address() tuples (e.g. an 8-element tuple for IPv6). Passing a string could lead to failed or unreliable IPv6 connections.

This PR fixes both: DNS now falls back to AAAA when A returns nothing, and we parse IP strings to tuples before calling Gun so IPv6 addresses are in the correct form.

Changes

1. DNS resolver: AAAA fallback (grpc_client/lib/grpc/client/resolver/dns.ex)

  • If the A-record lookup returns no addresses, the resolver now falls back to an AAAA lookup so IPv6-only or dual-stack targets can be resolved.
  • Logic: try A first; if the result is an empty list, call lookup_addresses(host, :aaaa).

2. Gun adapter: parse host to tuple before open (grpc_client/lib/grpc/client/adapters/gun.ex)

  • Before calling :gun.open/3, the host is passed through a new parse_address/1 helper.
  • If the host is a valid IP string (IPv4 or IPv6), :inet.parse_address/1 is used and the resulting tuple is passed to :gun.open.
  • If parsing fails (e.g. hostname), the host is passed as a charlist as before.
  • This ensures IPv6 addresses (e.g. from AAAA) are given to Gun in the form it expects

Copy link
Collaborator

@sleipnir sleipnir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a test to verify this fallback?

@KalleJoP KalleJoP requested a review from sleipnir February 9, 2026 14:18
@sleipnir sleipnir requested a review from polvalente February 10, 2026 12:53
KalleJoP and others added 2 commits February 10, 2026 17:55
Co-authored-by: Paulo Valente <16843419+polvalente@users.noreply.github.com>
Co-authored-by: Paulo Valente <16843419+polvalente@users.noreply.github.com>
@KalleJoP
Copy link
Contributor Author

Thanks for the reviews! 👍

@KalleJoP KalleJoP requested a review from polvalente February 10, 2026 16:57
@polvalente polvalente merged commit 85ccf20 into elixir-grpc:master Feb 10, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants