Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd30d27a

Browse files
committed
Client-side fixes for delayed NOTIFY receipt.
PQnotifies() is defined to just process already-read data, not try to readany more from the socket. (This is a debatable decision, perhaps, but I'mhesitant to change longstanding library behavior.) The documentation haslong recommended calling PQconsumeInput() before PQnotifies() to ensurethat any already-arrived message would get absorbed and processed.However, psql did not get that memo, which explains why it's not veryreliable about reporting notifications promptly.Also, most (not quite all) callers called PQconsumeInput() just once beforea PQnotifies() loop. Taking this recommendation seriously implies that weshould do PQconsumeInput() before each call. This is more important nowthat we have "payload" strings in notification messages than it was before;that increases the probability of having more than one packet's worthof notify messages. Hence, adjust code as well as documentation examplesto do it like that.Back-patch to 9.5 to match related server fixes. In principle we couldprobably go back further with these changes, but given lack of fieldcomplaints I doubt it's worthwhile.Discussion:https://postgr.es/m/CAOYf6ec-TmRYjKBXLLaGaB-jrd=mjG1Hzn1a1wufUAR39PQYhw@mail.gmail.com
1 parent7aaeb7b commitd30d27a

File tree

5 files changed

+12
-4
lines changed

5 files changed

+12
-4
lines changed

‎doc/src/sgml/libpq.sgml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5284,7 +5284,7 @@ typedef struct pgNotify
52845284
<para>
52855285
<function>PQnotifies</function> does not actually read data from the
52865286
server; it just returns messages previously absorbed by another
5287-
<application>libpq</application> function. Inprior releases of
5287+
<application>libpq</application> function. Inancient releases of
52885288
<application>libpq</application>, the only way to ensure timely receipt
52895289
of <command>NOTIFY</command> messages was to constantly submit commands, even
52905290
empty ones, and then check <function>PQnotifies</function> after each
@@ -8677,6 +8677,7 @@ main(int argc, char **argv)
86778677
notify->relname, notify->be_pid);
86788678
PQfreemem(notify);
86798679
nnotifies++;
8680+
PQconsumeInput(conn);
86808681
}
86818682
}
86828683

‎src/bin/psql/common.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,8 @@ PrintNotifications(void)
836836
{
837837
PGnotify*notify;
838838

839-
while ((notify=PQnotifies(pset.db)))
839+
PQconsumeInput(pset.db);
840+
while ((notify=PQnotifies(pset.db))!=NULL)
840841
{
841842
/* for backward compatibility, only show payload if nonempty */
842843
if (notify->extra[0])
@@ -847,6 +848,7 @@ PrintNotifications(void)
847848
notify->relname,notify->be_pid);
848849
fflush(pset.queryFout);
849850
PQfreemem(notify);
851+
PQconsumeInput(pset.db);
850852
}
851853
}
852854

‎src/interfaces/ecpg/ecpglib/execute.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,12 +1729,13 @@ ecpg_process_output(struct statement *stmt, bool clear_result)
17291729
}
17301730

17311731
/* check for asynchronous returns */
1732-
notify=PQnotifies(stmt->connection->connection);
1733-
if (notify)
1732+
PQconsumeInput(stmt->connection->connection);
1733+
while ((notify=PQnotifies(stmt->connection->connection))!=NULL)
17341734
{
17351735
ecpg_log("ecpg_process_output on line %d: asynchronous notification of \"%s\" from backend PID %d received\n",
17361736
stmt->lineno,notify->relname,notify->be_pid);
17371737
PQfreemem(notify);
1738+
PQconsumeInput(stmt->connection->connection);
17381739
}
17391740

17401741
returnstatus;

‎src/interfaces/libpq/fe-exec.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2239,6 +2239,9 @@ PQsendDescribe(PGconn *conn, char desc_type, const char *desc_target)
22392239
* no unhandled async notification from the backend
22402240
*
22412241
* the CALLER is responsible for FREE'ing the structure returned
2242+
*
2243+
* Note that this function does not read any new data from the socket;
2244+
* so usually, caller should call PQconsumeInput() first.
22422245
*/
22432246
PGnotify*
22442247
PQnotifies(PGconn*conn)

‎src/test/examples/testlibpq2.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ main(int argc, char **argv)
140140
notify->relname,notify->be_pid);
141141
PQfreemem(notify);
142142
nnotifies++;
143+
PQconsumeInput(conn);
143144
}
144145
}
145146

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp