Tue, 25 Jan 2022 17:45:56 +0100
don't fail webserver init in case a resourcepool ping fails
--- a/src/server/daemon/resourcepool.c Sat Jan 22 19:13:40 2022 +0100 +++ b/src/server/daemon/resourcepool.c Tue Jan 25 17:45:56 2022 +0100 @@ -106,12 +106,6 @@ pthread_mutex_init(&respool->lock, NULL); pthread_cond_init(&respool->available, NULL); - if(resourcepool_create_resources(respool, respool->max)) { - log_ereport(LOG_FAILURE, "Resource pool %s: Cannot create resources", name.ptr); - resourcepool_destroy(respool); - return 1; - } - return 0; }
--- a/src/server/plugins/postgresql/resource.c Sat Jan 22 19:13:40 2022 +0100 +++ b/src/server/plugins/postgresql/resource.c Tue Jan 25 17:45:56 2022 +0100 @@ -51,10 +51,10 @@ // test connection PGconn *test_connection = PQconnectdb(connection); - if(pg_check_connection(rpname, test_connection)) { - return NULL; // error, pg_check_connection does the logging + if(pg_check_connection(LOG_WARN, rpname, test_connection)) { + log_ereport(LOG_WARN, "Resource pool %s: Connection check failed", rpname); } - PQfinish(test_connection); + if(test_connection) PQfinish(test_connection); PgResourcePool *pg = pool_malloc(pool, sizeof(PgResourcePool)); if(!pg) { @@ -68,9 +68,9 @@ } -int pg_check_connection(const char *rpname, PGconn *connection) { +int pg_check_connection(int loglevel, const char *rpname, PGconn *connection) { if(!connection) { - log_ereport(LOG_FAILURE, "Resource pool %s: Cannot create PQ connection", rpname); + log_ereport(loglevel, "Resource pool %s: Cannot create PQ connection", rpname); return 1; } if(PQstatus(connection) != CONNECTION_OK) { @@ -82,7 +82,7 @@ errlen--; } } - log_ereport(LOG_FAILURE, "Resource pool %s: Failed to connect to database: %.*s", rpname, errlen, err); + log_ereport(loglevel, "Resource pool %s: Failed to connect to database: %.*s", rpname, errlen, err); PQfinish(connection); return 1; } @@ -96,7 +96,7 @@ void * pg_resourcepool_createresource(PgResourcePool *pg) { PGconn *connection = PQconnectdb(pg->connection); - if(pg_check_connection(pg->name, connection)) { + if(pg_check_connection(LOG_FAILURE, pg->name, connection)) { return NULL; }
--- a/src/server/plugins/postgresql/resource.h Sat Jan 22 19:13:40 2022 +0100 +++ b/src/server/plugins/postgresql/resource.h Tue Jan 25 17:45:56 2022 +0100 @@ -81,7 +81,7 @@ * if conn is not null but the status is not CONNECTION_OK, * conn will be destroyed */ -int pg_check_connection(const char *rpname, PGconn *connection); +int pg_check_connection(int loglevel, const char *rpname, PGconn *connection); #ifdef __cplusplus }