ruby-pg
ruby-pg copied to clipboard
try the next host on connnect_timeout
closes: #618
libpq does not support connect_timeout when using the async api.
So when using the async connection API with a multi-host connection string libpq will never timeout connections to the first host in the list and will not try try subsequent hosts in the connection string list.
This fixes this by closing and reopenning the connection with a reordered connection string if the connection to a host times out.
See discussion on the pgsql-hackers list discussing this "feature" of the api: https://www.postgresql.org/message-id/flat/CA%2Bmi_8YyGKA9dWELu63e%3DKL2oN-%2BFe4uca4EtFfb6uQD4Up8pw%40mail.gmail.com
@larskanis any feedback?
Thank very much you for this PR! Somehow I had the opinion, that this is already implemented. But it is not!
I'll try to add some useful tests for it and will probably add an error message that mentions multiple host connection attempts, like libpq does in blocking mode:
$ psql "host=11.11.11.11,22.22.22.22 connect_timeout=5"
psql: error: connection to server at "11.11.11.11", port 5432 failed: timeout expired
connection to server at "22.22.22.22", port 5432 failed: timeout expired