postgresql-jdbc.git / summary / log / commit / refs

commit    b2eaefef1787b8ab0b8fcb266d10be4945a4fe25
Author:   Adrien <arobert@delfingen.com>
Commit:   Dave Cramer <davecramer@gmail.com>
Date:     Thu Sep 05 15:27:16 2019 +0000

    Ensure isValid() will not last more than timeout seconds (#1557)
    
    * Ensure isValid() will not last more than timeout seconds
    even if the underlying socket is broken (issue #1556)
    
    * Fix check style
    
    * Add a try/catch to succeed tests
    
    * Manages simply and properly get/setNetworkTimeout() in isValid()


.../java/org/postgresql/jdbc/PgConnection.java | 26 +++++++++++++--------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/pgjdbc/src/main/java/org/postgresql/jdbc/PgConnection.java b/pgjdbc/src/main/java/org/postgresql/jdbc/PgConnection.java index b31b11f9..aeba6102 100644 --- a/pgjdbc/src/main/java/org/postgresql/jdbc/PgConnection.java +++ b/pgjdbc/src/main/java/org/postgresql/jdbc/PgConnection.java @@ -1379,18 +1379,24 @@ public class PgConnection implements BaseConnection { return false; } try { - if (replicationConnection) { - Statement statement = createStatement(); - statement.execute("IDENTIFY_SYSTEM"); - statement.close(); - } else { - if (checkConnectionQuery == null) { - checkConnectionQuery = prepareStatement(""); + int savedNetworkTimeOut = getNetworkTimeout(); + try { + setNetworkTimeout(null, timeout * 1000); + if (replicationConnection) { + Statement statement = createStatement(); + statement.execute("IDENTIFY_SYSTEM"); + statement.close(); + } else { + if (checkConnectionQuery == null) { + checkConnectionQuery = prepareStatement(""); + } + checkConnectionQuery.setQueryTimeout(timeout); + checkConnectionQuery.executeUpdate(); } - checkConnectionQuery.setQueryTimeout(timeout); - checkConnectionQuery.executeUpdate(); + return true; + } finally { + setNetworkTimeout(null, savedNetworkTimeOut); } - return true; } catch (SQLException e) { if (PSQLState.IN_FAILED_SQL_TRANSACTION.getState().equals(e.getSQLState())) { // "current transaction aborted", assume the connection is up and running [parent: 8495127fe045]