Commit 36c9a01a authored by Tom Lane's avatar Tom Lane

Avoid infinite loop if connection is lost during PQexecStart() or

PQexecFinish().  Per report from Andreas Pflug.
parent f8eed65d
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-exec.c,v 1.155 2003/11/30 20:55:09 joe Exp $ * $PostgreSQL: pgsql/src/interfaces/libpq/fe-exec.c,v 1.156 2003/12/28 17:29:41 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -1234,6 +1234,9 @@ PQexecStart(PGconn *conn) ...@@ -1234,6 +1234,9 @@ PQexecStart(PGconn *conn)
return false; return false;
} }
} }
/* check for loss of connection, too */
if (conn->status == CONNECTION_BAD)
return false;
} }
/* OK to send a command */ /* OK to send a command */
...@@ -1256,6 +1259,8 @@ PQexecFinish(PGconn *conn) ...@@ -1256,6 +1259,8 @@ PQexecFinish(PGconn *conn)
* *
* We have to stop if we see copy in/out, however. We will resume parsing * We have to stop if we see copy in/out, however. We will resume parsing
* after application performs the data transfer. * after application performs the data transfer.
*
* Also stop if the connection is lost (else we'll loop infinitely).
*/ */
lastResult = NULL; lastResult = NULL;
while ((result = PQgetResult(conn)) != NULL) while ((result = PQgetResult(conn)) != NULL)
...@@ -1281,7 +1286,8 @@ PQexecFinish(PGconn *conn) ...@@ -1281,7 +1286,8 @@ PQexecFinish(PGconn *conn)
} }
lastResult = result; lastResult = result;
if (result->resultStatus == PGRES_COPY_IN || if (result->resultStatus == PGRES_COPY_IN ||
result->resultStatus == PGRES_COPY_OUT) result->resultStatus == PGRES_COPY_OUT ||
conn->status == CONNECTION_BAD)
break; break;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment