xandra icon indicating copy to clipboard operation
xandra copied to clipboard

Support IPv6 nodes and transport options

Open erhlee-bird opened this issue 1 year ago • 0 comments

Hi there, thanks for the awesome library!

I'm running infrastructure on a platform called fly.io which runs IPv6 private networks. I was unable to connect to my ScyllaDB cluster using Xandra and found that there were a few limitations to IPv6 support.

This pull request adds proposed fixes for the below 2 issues. I've added some tests and tried to ensure that this change would not break Xandra.start_link() and Xandra.Cluster.start_link() but there may be other places using these options that I may have missed.

In my fork, I'm now able to establish an IPv6 connection to my cluster and get kicked back due to lack of authentication whereas before connections would hang or hit sync_connection_timeout errors.

iex(1)> Xandra.start_link(nodes: ["my-scylla-cluster.internal"], transport_options: [:inet6])     
{:ok, #PID<0.2711.0>}
** (EXIT from #PID<0.2710.0>) shell process exited with reason: an exception was raised:
    ** (RuntimeError) Cassandra server requires authentication but the :authentication option was not provided
        (xandra 0.19.1) lib/xandra/protocol/v4.ex:48: Xandra.Protocol.V4.encode_request/3
        (xandra 0.19.1) lib/xandra/connection/utils.ex:143: Xandra.Connection.Utils.authenticate_connection/5
        (xandra 0.19.1) lib/xandra/connection.ex:458: Xandra.Connection.disconnected/3
        (stdlib 4.3.1.5) gen_statem.erl:1426: :gen_statem.loop_state_callback/11
        (stdlib 4.3.1.5) proc_lib.erl:240: :proc_lib.init_p_do_apply/3

Cannot specify IPv6 node addresses.

iex(1)> Xandra.start_link(nodes: ["::1"])   
** (NimbleOptions.ValidationError) invalid list in :nodes option: invalid value for list element at position 0: invalid node: "::1"
    (nimble_options 1.1.1) lib/nimble_options.ex:359: NimbleOptions.validate!/2
    (xandra 0.19.1) lib/xandra.ex:508: Xandra.start_link/1
    iex:1: (file)

Cannot pass :inet6 as a transport option for :gen_tcp

iex(1)> Xandra.start_link(nodes: ["localhost"], transport_options: [:inet6])
** (NimbleOptions.ValidationError) invalid value for :transport_options option: expected keyword list, got: [:inet6]
    (nimble_options 1.1.1) lib/nimble_options.ex:359: NimbleOptions.validate!/2
    (xandra 0.19.1) lib/xandra.ex:508: Xandra.start_link/1
    iex:1: (file)

:gen_tcp accepts options that are not strictly keywords.

iex(2)> :gen_tcp.connect('my-scylla-cluster.internal', 9042, [:inet6])
{:ok, #Port<0.27>}
iex(3)> :gen_tcp.connect('my-scylla-cluster.internal', 9042, [{:inet6, true}])
{:error, :nxdomain}
iex(4)> :gen_tcp.connect('my-scylla-cluster.internal', 9042, [inet6: true])
{:error, :nxdomain}

erhlee-bird avatar Dec 04 '24 21:12 erhlee-bird