Skip to content

Commit 36c9a01

Browse files
committed
Avoid infinite loop if connection is lost during PQexecStart() or
PQexecFinish(). Per report from Andreas Pflug.
1 parent f8eed65 commit 36c9a01

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/interfaces/libpq/fe-exec.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-exec.c,v 1.155 2003/11/30 20:55:09 joe Exp $
11+
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-exec.c,v 1.156 2003/12/28 17:29:41 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1234,6 +1234,9 @@ PQexecStart(PGconn *conn)
12341234
return false;
12351235
}
12361236
}
1237+
/* check for loss of connection, too */
1238+
if (conn->status == CONNECTION_BAD)
1239+
return false;
12371240
}
12381241

12391242
/* OK to send a command */
@@ -1256,6 +1259,8 @@ PQexecFinish(PGconn *conn)
12561259
*
12571260
* We have to stop if we see copy in/out, however. We will resume parsing
12581261
* after application performs the data transfer.
1262+
*
1263+
* Also stop if the connection is lost (else we'll loop infinitely).
12591264
*/
12601265
lastResult = NULL;
12611266
while ((result = PQgetResult(conn)) != NULL)
@@ -1281,7 +1286,8 @@ PQexecFinish(PGconn *conn)
12811286
}
12821287
lastResult = result;
12831288
if (result->resultStatus == PGRES_COPY_IN ||
1284-
result->resultStatus == PGRES_COPY_OUT)
1289+
result->resultStatus == PGRES_COPY_OUT ||
1290+
conn->status == CONNECTION_BAD)
12851291
break;
12861292
}
12871293

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy