diff --git a/mbuni/ChangeLog b/mbuni/ChangeLog index 5aa0e56..7b73d9a 100644 --- a/mbuni/ChangeLog +++ b/mbuni/ChangeLog @@ -1,3 +1,5 @@ +2009-03-01 P. A. Bagyenda + * pgsql-queue module fix: Connection pool should return only valid (active) connections 2009-02-25 P. A. Bagyenda * Added ChargedParty MM7/SOAP param to mmsbox * Fixed: Improper setting of log level diff --git a/mbuni/extras/pgsql-queue/mms_pgsql_queue.c b/mbuni/extras/pgsql-queue/mms_pgsql_queue.c index 274a9c6..9873309 100644 --- a/mbuni/extras/pgsql-queue/mms_pgsql_queue.c +++ b/mbuni/extras/pgsql-queue/mms_pgsql_queue.c @@ -159,12 +159,20 @@ static PGconn *get_conn_real(const char *function, const char *file, const int l /* debug("pg_cp",0, "pg_get_conn> %s:%d, %s => %d", file, line, function, (int)c); */ - if (c) { /* might fail if we are shutting down. */ + if (c && PQstatus(c) == CONNECTION_OK) { /* might fail if we are shutting down. */ r = PQexec(c, "BEGIN"); /* start a transaction. */ PQclear(r); - } else - mms_error(0, "pgsql_queue", NULL, "pg_get_conn: Failed to get a free connection from connection pool! Consider increasing pool size (currently %d)?", - pool_size); + } else { + mms_error(0, "pgsql_queue", NULL, + "pg_get_conn: Failed to get a free connection [%s] from connection pool! " + " Consider increasing pool size (currently %d)?", + c ? "NOT CONNECTED" : "TIMEOUT", + pool_size); + if (c) { + PQfinish(c); + c = NULL; + } + } return c; } @@ -182,7 +190,10 @@ static void return_conn_real(PGconn *c, const char *function, const char *file, else r = PQexec(c, "COMMIT"); PQclear(r); - gwlist_produce(free_conns,c); + if (PQstatus(c) == CONNECTION_OK) + gwlist_produce(free_conns,c); + else + PQfinish(c); }