2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-31 22:15:23 +00:00

[#2734] tcp_user_timeout for PostgreSQL 12+

Added conditional compilation to set tcp_user_timeout parameter for the
PostgreSQL 12 or later. Log a warning for earlier PostgreSQL versions.
This commit is contained in:
Marcin Siodelski
2023-02-05 21:51:56 +01:00
parent 6292551b6a
commit fc3c4794b7
6 changed files with 38 additions and 16 deletions

View File

@@ -802,6 +802,7 @@ if test "$PG_CONFIG" != "" ; then
PGSQL_LIBS=`$PG_CONFIG --libdir`
PGSQL_LIBS="-L$PGSQL_LIBS -lpq"
PGSQL_VERSION=`$PG_CONFIG --version`
PGSQL_MAJOR_VERSION=`$PG_CONFIG --version | cut -f2 -d' ' | cut -f1 -d'.'`
AC_SUBST(PGSQL_CPPFLAGS)
AC_SUBST(PGSQL_LIBS)
@@ -831,6 +832,10 @@ if test "$PG_CONFIG" != "" ; then
# Note that PostgreSQL is present in the config.h file
AC_DEFINE([HAVE_PGSQL], [1], [PostgreSQL is present])
if test $PGSQL_MAJOR_VERSION -ge 12; then
AC_DEFINE([HAVE_PGSQL_TCP_USER_TIMEOUT], [1], [PostgreSQL connection parameter tcp_user_timeout supported])
fi
fi
# ... and at the shell level, so Makefile.am can take action depending on this.

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2018-2023 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -31,6 +31,7 @@ const DbLogger::MessageMap db_message_map = {
{ PGSQL_ROLLBACK, DATABASE_PGSQL_ROLLBACK },
{ PGSQL_CREATE_SAVEPOINT, DATABASE_PGSQL_CREATE_SAVEPOINT },
{ PGSQL_ROLLBACK_SAVEPOINT, DATABASE_PGSQL_ROLLBACK_SAVEPOINT },
{ PGSQL_TCP_USER_TIMEOUT_UNSUPPORTED, DATABASE_PGSQL_TCP_USER_TIMEOUT_UNSUPPORTED },
{ MYSQL_FATAL_ERROR, DATABASE_MYSQL_FATAL_ERROR },
{ MYSQL_START_TRANSACTION, DATABASE_MYSQL_START_TRANSACTION },

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2018-2022 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2018-2023 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -58,6 +58,7 @@ enum DbMessageID {
PGSQL_ROLLBACK,
PGSQL_CREATE_SAVEPOINT,
PGSQL_ROLLBACK_SAVEPOINT,
PGSQL_TCP_USER_TIMEOUT_UNSUPPORTED,
MYSQL_FATAL_ERROR,
MYSQL_START_TRANSACTION,

View File

@@ -80,6 +80,12 @@ inserted into multiple tables with multiple INSERT statements
and there may be a need to rollback the whole transaction if
any of these INSERT statements fail.
% DATABASE_PGSQL_TCP_USER_TIMEOUT_UNSUPPORTED tcp_user_timeout is not supported in this PostgreSQL version
This warning message is issued when a user has configured the tcp_user_timeout
parameter in the connection to the PostgreSQL database but the installed database
does not support this parameter. This parameter is supported by the PostgreSQL
version 12 or later. The parameter setting will be ignored.
% DATABASE_TO_JSON_BOOLEAN_ERROR Internal logic error: invalid boolean value found in database connection parameters: %1=%2
This error message is printed when conversion to JSON of the internal state is requested,
but the connection string contains a boolean parameter with invalid value. It is a programming

View File

@@ -249,11 +249,17 @@ PgSqlConnection::getConnParameters() {
isc_throw(DbInvalidTimeout, ex.what());
}
// Append timeouts.
// Append connection timeout.
std::ostringstream oss;
oss << " connect_timeout = " << connect_timeout;
if (tcp_user_timeout > 0) {
// tcp_user_timeout parameter is a PostgreSQL 12+ feature.
#ifdef HAVE_PGSQL_TCP_USER_TIMEOUT
oss << " tcp_user_timeout = " << tcp_user_timeout * 1000;
#else
DB_LOG_WARN(PGSQL_TCP_USER_TIMEOUT_UNSUPPORTED).arg();
#endif
}
dbconnparameters += oss.str();

View File

@@ -611,7 +611,9 @@ TEST_F(PgSqlConnectionTest, connectionTimeoutInvalid3) {
EXPECT_THROW(conn.getConnParameters(), DbInvalidTimeout);
}
// Tests that valid tcp user timeout is accepted.
// Tests that valid tcp user timeout is accepted. This parameter is
// supported by PostgreSQL 12 and later.
#ifdef HAVE_PGSQL_TCP_USER_TIMEOUT
TEST_F(PgSqlConnectionTest, tcpUserTimeout) {
std::string conn_str = connectionString(PGSQL_VALID_TYPE, VALID_NAME,
VALID_USER, VALID_PASSWORD,
@@ -622,6 +624,7 @@ TEST_F(PgSqlConnectionTest, tcpUserTimeout) {
EXPECT_TRUE(parameters.find("tcp_user_timeout = 8000") != std::string::npos)
<< "parameter not found in " << parameters;
}
#endif
// Tests that a zero tcp user timeout is accepted.
TEST_F(PgSqlConnectionTest, tcpUserTimeoutZero) {