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 03339a3f8..aa331c2e2 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 @@ public class PostgreSQLAuthenticationProviderModule implements Module { } + // 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 8142d9c04..d7e4daeee 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 @@ -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) { 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 3295d7775..128b5c348 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 @@ -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 diff --git a/guacamole-docker/bin/start.sh b/guacamole-docker/bin/start.sh index d661d1a23..6bc6ee8fb 100755 --- a/guacamole-docker/bin/start.sh +++ b/guacamole-docker/bin/start.sh @@ -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"