GUACAMOLE-919: pass postgres driver socketTimout

This commit is contained in:
Douglas Heriot
2020-03-23 21:52:29 +11:00
parent 34130f54c9
commit 306e1ad3ab
4 changed files with 44 additions and 1 deletions

View File

@@ -111,6 +111,9 @@ public class PostgreSQLAuthenticationProviderModule implements Module {
}
// Handle case where TCP connection to database is silently dropped
driverProperties.setProperty("socketTimeout", String.valueOf(environment.getPostgreSQLSocketTimeout()));
}
@Override

View File

@@ -56,6 +56,13 @@ public class PostgreSQLEnvironment extends JDBCEnvironment {
*/
private static final String DEFAULT_DEFAULT_STATEMENT_TIMEOUT = "null";
/**
* The default socketTimeout (in seconds), if POSTGRESQL_SOCKET_TIMEOUT is not specified.
* Default to 0 (no timeout)
* https://jdbc.postgresql.org/documentation/head/connect.html
*/
private static final int DEFAULT_SOCKET_TIMEOUT = 0;
/**
* Whether a database user account is required by default for authentication
* to succeed.
@@ -257,7 +264,7 @@ public class PostgreSQLEnvironment extends JDBCEnvironment {
public String getPostgreSQLPassword() throws GuacamoleException {
return getRequiredProperty(PostgreSQLGuacamoleProperties.POSTGRESQL_PASSWORD);
}
/**
* Returns the defaultStatementTimeout set for PostgreSQL connections.
* If unspecified, this will be the default "null" (no timeout)
@@ -274,6 +281,23 @@ public class PostgreSQLEnvironment extends JDBCEnvironment {
DEFAULT_DEFAULT_STATEMENT_TIMEOUT
);
}
/**
* Returns the socketTimeout property to set on PostgreSQL connections.
* If unspecified, this will be the default to 0 (no timeout)
*
* @return
* The socketTimeout to use when waiting on read operations (in seconds)
*
* @throws GuacamoleException
* If an error occurs while retrieving the property value.
*/
public int getPostgreSQLSocketTimeout() throws GuacamoleException {
return getProperty(
PostgreSQLGuacamoleProperties.POSTGRESQL_SOCKET_TIMEOUT,
DEFAULT_SOCKET_TIMEOUT
);
}
@Override
public boolean isRecursiveQuerySupported(SqlSession session) {

View File

@@ -106,6 +106,18 @@ public class PostgreSQLGuacamoleProperties {
};
/**
* Sets the number of seconds the driver will wait in a read() call
* on the TCP connection to the database.
*/
public static final IntegerGuacamoleProperty
POSTGRESQL_SOCKET_TIMEOUT = new IntegerGuacamoleProperty(){
@Override
public String getName() { return "postgresql-socket-timeout"; }
};
/**
* Whether a user account within the database is required for authentication
* to succeed, even if the user has been authenticated via another

View File

@@ -362,6 +362,10 @@ END
"postgresql-user-required" \
"$POSTGRES_USER_REQUIRED"
set_optional_property \
"postgresql-socket-timeout" \
"$POSTGRES_SOCKET_TIMEOUT"
set_optional_property \
"postgresql-ssl-mode" \
"$POSTGRESQL_SSL_MODE"