summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane2003-10-02 19:52:44 +0000
committerTom Lane2003-10-02 19:52:44 +0000
commitb4966453f6213f65777ab289c996b319a63bbc70 (patch)
treed17a3bbc4857fbc8e44f42e8b85d43fcef8a4906 /src
parentbf2f5d9463082d92835655aafa02f403763ebf40 (diff)
Do not return from PQrequestCancel until postmaster has finished
processing the request; this ensures that the request won't be taken to cancel a subsequently-issued query. Race condition originally noted by Oliver Jowett in the context of JDBC, but libpq has it too.
Diffstat (limited to 'src')
-rw-r--r--src/interfaces/libpq/fe-connect.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index c0526b75bf3..cd235a12768 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.261 2003/09/22 00:23:35 petere Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.262 2003/10/02 19:52:44 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -2262,7 +2262,23 @@ retry4:
goto cancel_errReturn;
}
- /* Sent it, done */
+ /*
+ * Wait for the postmaster to close the connection, which indicates that
+ * it's processed the request. Without this delay, we might issue another
+ * command only to find that our cancel zaps that command instead of the
+ * one we thought we were canceling. Note we don't actually expect this
+ * read to obtain any data, we are just waiting for EOF to be signaled.
+ */
+retry5:
+ if (recv(tmpsock, (char *) &crp, 1, 0) < 0)
+ {
+ if (SOCK_ERRNO == EINTR)
+ /* Interrupted system call - we'll just try again */
+ goto retry5;
+ /* we ignore other error conditions */
+ }
+
+ /* All done */
closesocket(tmpsock);
#ifdef WIN32
WSASetLastError(save_errno);