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

Add more information to "connect timeout" errors: include hosts attempted, hosts skipped, timeout values #3189

Open
vlsi opened this issue Apr 5, 2024 · 1 comment

Comments

@vlsi
Copy link
Member

vlsi commented Apr 5, 2024

If loginTimeout is less than connectTimeout * numberOfHosts, then the connect operation might fail in case the first attempted replicas take a lot of time to connect.

The error message could probably include "attempted these hosts: ..., skipped hosts ... due to loginTimeout=... reached. Consider increasing loginTimeout or decreasing connectTimeout".

@vlsi vlsi changed the title Add more information to "connect timeout" errors: include hosts attempted, timeout values Add more information to "connect timeout" errors: include hosts attempted, hosts skipped, timeout values Apr 5, 2024
@imranzaheer612
Copy link
Contributor

imranzaheer612 commented Apr 6, 2024

Reproducing Error

I was able to reproduce the error. The first node here is unreachable but he second one works.

         Class.forName("org.postgresql.Driver");
         String url = "jdbc:postgresql://172.19.112.5:5334,172.19.112.6:5335/postgres";
         Properties props = new Properties();
         props.setProperty("user", "postgres");
         props.setProperty("password", "postgres");
         props.setProperty("loginTimeout", "5");

this caused generating the error.

org.postgresql.util.PSQLException: Connection attempt timed out.

Adding property of props.setProperty("connectTimeout", "1"); you can remove this error and the connection will be successfull.

Some Improvement

I tried adding more info but so far I was only able to add the loginTimeout.
In Driver.java added this piece of code

throw new RuntimeException(GT.tr("Interrupted while attempting to connect."));

          throw new PSQLException(GT.tr("Connection attempt timed out. Logintimeout=: " + TimeUnit.MILLISECONDS.toSeconds(timeout) + "reached."),

Now the errors looks like

org.postgresql.util.PSQLException: Connection attempt timed out. Logintimeout: 5 reached

Some remedy to get attempted and skippedHosts

There is a local variable knownStates in openConnectionImpl we can calculate the attemptedHosts from here. But its a local variable.
If we can propagate this from ConnectionFactoryImpl.java to Driver.java we can have some more info for the error message.

Map<HostSpec, HostStatus> knownStates = new HashMap<>();

Kindly share your thoughts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants