Message-ID: From: "Frankqsy (@Frankqsy)" To: "pgjdbc/pgjdbc" Date: Sun, 23 Jul 2017 14:03:56 +0000 Subject: [pgjdbc/pgjdbc] issue #879: loginTimeout in java.sql.DriverManager never be used List-Id: X-GitHub-Author-Id: 4224859 X-GitHub-Author-Login: Frankqsy X-GitHub-Issue: 879 X-GitHub-Labels: easy X-GitHub-Repo: pgjdbc/pgjdbc X-GitHub-State: open X-GitHub-Type: issue X-GitHub-Url: https://github.com/pgjdbc/pgjdbc/issues/879 Content-Type: text/plain; charset=utf-8 in the file:pgjdbc/src/main/java/org/postgresql/PGProperty.java,line 246. ``` LOGIN_TIMEOUT("loginTimeout", "0", "Specify how long to wait for establishment of a database connection."); ``` the default value "0" will lead to the result that the value set in DriverManager never be used.because the code using the value as follows: in the file:pgjdbc/pgjdbc/src/main/java/org/postgresql/Driver.java,line 633 ``` private static long timeout(Properties props) { String timeout = PGProperty.LOGIN_TIMEOUT.get(props); if (timeout != null) { try { return (long) (Float.parseFloat(timeout) * 1000); } catch (NumberFormatException e) { LOGGER.log(Level.WARNING, "Couldn't parse loginTimeout value: {0}", timeout); } } return (long) DriverManager.getLoginTimeout() * 1000; } ``` and in the method "get" of PGProperty,the code as follows: in the file:pgjdbc/src/main/java/org/postgresql/PGProperty.java,line 475. ``` public String get(Properties properties) { return properties.getProperty(_name, _defaultValue); } ``` as above,the LOGIN_TIMEOUT will always get the default value of "0",the loginTimeout value set in the DriverManager will never be used. if we want to set the loginTimeout, we must put it into properties,this will make confusion when we develop. The phenomenon will be that the login will hang if the network is error although we have set the loginTimeout value in the DriverManager.