GUACAMOLE-919: pass postgres driver socketTimout
diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/PostgreSQLAuthenticationProviderModule.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/PostgreSQLAuthenticationProviderModule.java
index 03339a3..aa331c2 100644
--- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/PostgreSQLAuthenticationProviderModule.java
+++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/PostgreSQLAuthenticationProviderModule.java
@@ -111,6 +111,9 @@
}
+ // Handle case where TCP connection to database is silently dropped
+ driverProperties.setProperty("socketTimeout", String.valueOf(environment.getPostgreSQLSocketTimeout()));
+
}
@Override
diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/conf/PostgreSQLEnvironment.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/conf/PostgreSQLEnvironment.java
index 8142d9c..d7e4dae 100644
--- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/conf/PostgreSQLEnvironment.java
+++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/conf/PostgreSQLEnvironment.java
@@ -57,6 +57,13 @@
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 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 @@
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) {
diff --git a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/conf/PostgreSQLGuacamoleProperties.java b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/conf/PostgreSQLGuacamoleProperties.java
index 3295d77..128b5c3 100644
--- a/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/conf/PostgreSQLGuacamoleProperties.java
+++ b/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-postgresql/src/main/java/org/apache/guacamole/auth/postgresql/conf/PostgreSQLGuacamoleProperties.java
@@ -107,6 +107,18 @@
};
/**
+ * 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
* authentication provider.
diff --git a/guacamole-docker/bin/start.sh b/guacamole-docker/bin/start.sh
index d661d1a..6bc6ee8 100755
--- a/guacamole-docker/bin/start.sh
+++ b/guacamole-docker/bin/start.sh
@@ -362,6 +362,10 @@
"postgresql-user-required" \
"$POSTGRES_USER_REQUIRED"
+ set_optional_property \
+ "postgresql-socket-timeout" \
+ "$POSTGRES_SOCKET_TIMEOUT"
+
set_optional_property \
"postgresql-ssl-mode" \
"$POSTGRESQL_SSL_MODE"