postgrex icon indicating copy to clipboard operation
postgrex copied to clipboard

Extra options per connection endpoint are ignored

Open msfstef opened this issue 11 months ago • 2 comments

Elixir version

1.18.1

Database and Version

17

Postgrex Version

0.19.0

Current behavior

Specifying the start_link connection options as:

endpoints: [
        {hostname, port, socket_options: [:inet6]},
        {hostname, port, socket_options: [:inet]}
]

Results in a warning

[warning] Returning a triplet from :endpoints is deprecated, the server name indicator is automatically set based on the hostname if SSL is enabled

And the options are not respected - and looking at the source they seem to be completely discarded: https://github.com/elixir-ecto/postgrex/blob/34a57fe359a39488b673cec041829846e26ba758/lib/postgrex/protocol.ex#L192-L196

Expected behavior

We want to be able to fallback from IPv6 to IPv4, and potentially also try different SSL options, and the endpoints option is currently documented to accept extra options.

If the library had the documented behaviour it would be very convenient for implementing fallbacks in configuration options - is the lack of support of options per endpoint an intentional decision, and would it potentially be reinstated?

msfstef avatar Feb 03 '25 12:02 msfstef

It could be reinstated. Can you please provide more details on what you want to achieve? The reason it was removed is because we have better defaults that work across different situations. For example, it may work now without additional extra options. Meanwhile I will update the docs.

josevalim avatar Feb 03 '25 13:02 josevalim

The main reason we were looking at the endpoints with extra options per endpoint was to be able to always try to connect using IPv6 and fallback to IPv4 if the former is not resolvable. See https://github.com/erlang/otp/issues/8548 for a more general description of the issue, where someone suggested Postgrex's endpoints option.

The ideal situation would be for a database URL to be provided, and for no specification of whether we should use IPv6 or IPv4 to connect to it to be needed and for the connection to succeed, for IPv4-only, IPv6-only, and with a preference for IPv6 if both are available.

edit: there is a similar situation with wanting to try different SSL configurations and having fallbacks there, but less important than the IPv6 to IPv4 fallback described above

msfstef avatar Feb 03 '25 13:02 msfstef