Skip to content

Commit bbebcb1

Browse files
committed
Fixes:
Async notifies received while a backend is in the middle of a begin/end transaction block are lost by libpq when the final end command is issued. The bug is in the routine PQexec of libpq. The routine throws away any message from the backend when a message of type 'C' is received. This type of message is sent when the result of a portal query command with no tuples is returned. Unfortunately this is the case of the end command. As all async notification are sent only when the transaction is finished, if they are received in the middle of a transaction they are lost in the libpq library. I added some tracing code to PQexec and this is the output: Submitted by: Massimo Dal Zotto <dz@cs.unitn.it>
1 parent e3b41d4 commit bbebcb1

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/interfaces/libpq/fe-exec.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.17 1996/08/14 16:44:51 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.18 1996/09/16 05:50:46 scrappy Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -370,6 +370,10 @@ PQexec(PGconn* conn, const char* query)
370370
PGnotify *newNotify;
371371
FILE *pfin, *pfout, *pfdebug;
372372

373+
#ifdef PQ_NOTIFY_PATCH
374+
int isCommand = 0; /* DZ - 31-8-1996 */
375+
#endif
376+
373377
pname[0]='\0';
374378

375379
if (!conn) return NULL;
@@ -457,6 +461,13 @@ PQexec(PGconn* conn, const char* query)
457461
clear = 0;
458462

459463
pqPuts("Q ",pfout,pfdebug); /* send an empty query */
464+
#ifdef PQ_NOTIFY_PATCH
465+
/*
466+
* Set a flag and process messages in the usual way because
467+
* there may be async notifications pending. DZ - 31-8-1996
468+
*/
469+
isCommand = 1;
470+
#else
460471
while (!clear)
461472
{
462473
if (pqGets(buffer,ERROR_MSG_LENGTH,pfin,pfdebug) == 1)
@@ -466,6 +477,7 @@ PQexec(PGconn* conn, const char* query)
466477
result = makeEmptyPGresult(conn,PGRES_COMMAND_OK);
467478
strncpy(result->cmdStatus,cmdStatus, CMDSTATUS_LEN-1);
468479
return result;
480+
#endif
469481
}
470482
break;
471483
case 'E': /* error return */
@@ -482,6 +494,17 @@ PQexec(PGconn* conn, const char* query)
482494
if ((c = pqGetc(pfin,pfdebug)) != '\0') {
483495
fprintf(stderr,"error!, unexpected character %c following 'I'\n", c);
484496
}
497+
#ifdef PQ_NOTIFY_PATCH
498+
if (isCommand) {
499+
/*
500+
* If this is the result of a portal query command set the
501+
* command status and message accordingly. DZ - 31-8-1996
502+
*/
503+
result = makeEmptyPGresult(conn,PGRES_COMMAND_OK);
504+
strncpy(result->cmdStatus,cmdStatus, CMDSTATUS_LEN-1);
505+
return result;
506+
}
507+
#endif
485508
result = makeEmptyPGresult(conn, PGRES_EMPTY_QUERY);
486509
return result;
487510
}

0 commit comments

Comments
 (0)