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

try the next host on connnect_timeout #619

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ajmaidak
Copy link

@ajmaidak ajmaidak commented Dec 23, 2024

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

@ajmaidak
Copy link
Author

ajmaidak commented Jan 3, 2025

@larskanis any feedback?

ajmaidak and others added 2 commits January 10, 2025 22:01
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 not timeout connections to the first host in the
list and thus will not attempt to connect to any subsequent hosts
in the connection string list.

This fixes this by closing and reopenning the connection with a
reordered connection string when connection 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 larskanis force-pushed the try-next-host-on-timeout branch from 616c6f9 to fe4b41c Compare January 10, 2025 21:03
@larskanis
Copy link
Collaborator

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

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.

async connection API does not properly handle timeouts with multiple hosts
2 participants