From: Timo Sirainen Date: Thu, 19 Jun 2003 01:59:11 +0000 (+0300) Subject: If query fails with fatal failure, reconnect. X-Git-Tag: 1.1.alpha1~4544 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c46e391fe627d386be82d3644427ab10deb690be;p=thirdparty%2Fdovecot%2Fcore.git If query fails with fatal failure, reconnect. --HG-- branch : HEAD --- diff --git a/src/auth/db-pgsql.c b/src/auth/db-pgsql.c index 5efe6fee03..821b289967 100644 --- a/src/auth/db-pgsql.c +++ b/src/auth/db-pgsql.c @@ -38,7 +38,7 @@ void db_pgsql_query(struct pgsql_connection *conn, const char *query, struct pgsql_request *request) { PGresult *res; - int failed; + int i, failed; if (!conn->connected) { if (!pgsql_conn_open(conn)) { @@ -50,14 +50,23 @@ void db_pgsql_query(struct pgsql_connection *conn, const char *query, if (verbose_debug) i_info("PGSQL: Performing query: %s", query); - res = PQexec(conn->pg, query); + for (i = 0; i < 2; i++) { + res = PQexec(conn->pg, query); - if (PQresultStatus(res) != PGRES_TUPLES_OK) { + if (PQresultStatus(res) != PGRES_FATAL_ERROR) + break; + + /* probably lost connection */ + i_info("PGSQL: Fatal error, reconnecting"); + PQreset(conn->pg); + } + + if (PQresultStatus(res) == PGRES_TUPLES_OK) + failed = FALSE; + else { i_error("PGSQL: Query \"%s\" failed: %s", query, PQresultErrorMessage(res)); failed = TRUE; - } else { - failed = FALSE; } request->callback(conn, request, failed ? NULL : res);