dovecot-1.2: pgsql: Fixes to handling reconnecting to server.
dovecot at dovecot.org
dovecot at dovecot.org
Sat Feb 7 00:40:14 EET 2009
details: http://hg.dovecot.org/dovecot-1.2/rev/b899076947cf
changeset: 8733:b899076947cf
user: Timo Sirainen <tss at iki.fi>
date: Fri Feb 06 17:40:10 2009 -0500
description:
pgsql: Fixes to handling reconnecting to server.
diffstat:
1 file changed, 14 insertions(+), 3 deletions(-)
src/lib-sql/driver-pgsql.c | 17 ++++++++++++++---
diffs (41 lines):
diff -r 4142c933e231 -r b899076947cf src/lib-sql/driver-pgsql.c
--- a/src/lib-sql/driver-pgsql.c Fri Feb 06 17:19:57 2009 -0500
+++ b/src/lib-sql/driver-pgsql.c Fri Feb 06 17:40:10 2009 -0500
@@ -254,7 +254,10 @@ static void consume_results(struct pgsql
return;
} while (PQgetResult(db->pg) != NULL);
- io_remove(&db->io);
+ if (PQstatus(db->pg) == CONNECTION_BAD)
+ io_remove_closed(&db->io);
+ else
+ io_remove(&db->io);
db->querying = FALSE;
if (db->queue != NULL && db->connected)
@@ -310,8 +313,12 @@ static void result_finish(struct pgsql_r
bool free_result = TRUE, retry = FALSE;
bool disconnected;
- disconnected = PQstatus(db->pg) == CONNECTION_BAD;
- if (disconnected && result->pgres == NULL && result->retry_query) {
+ /* if connection to server was lost, we don't yet see that the
+ connection is bad. we only see the fatal error, so assume it also
+ means disconnection. */
+ disconnected = PQstatus(db->pg) == CONNECTION_BAD ||
+ PQresultStatus(result->pgres) == PGRES_FATAL_ERROR;
+ if (disconnected && result->retry_query) {
/* retry the query */
i_error("pgsql: Query failed, retrying: %s", last_error(db));
retry = TRUE;
@@ -328,6 +335,10 @@ static void result_finish(struct pgsql_r
if (disconnected) {
/* disconnected */
+ if (result->pgres != NULL) {
+ PQclear(result->pgres);
+ result->pgres = NULL;
+ }
driver_pgsql_close(db);
if (retry) {
More information about the dovecot-cvs
mailing list