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

Commit4247db6

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 parent2ddb914 commit4247db6

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
@@ -8711,6 +8711,7 @@ main(int argc, char **argv)
87118711
notify->relname, notify->be_pid);
87128712
PQfreemem(notify);
87138713
nnotifies++;
8714+
PQconsumeInput(conn);
87148715
}
87158716
}
87168717

‎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
@@ -1722,12 +1722,13 @@ ecpg_process_output(struct statement *stmt, bool clear_result)
17221722
}
17231723

17241724
/* check for asynchronous returns */
1725-
notify=PQnotifies(stmt->connection->connection);
1726-
if (notify)
1725+
PQconsumeInput(stmt->connection->connection);
1726+
while ((notify=PQnotifies(stmt->connection->connection))!=NULL)
17271727
{
17281728
ecpg_log("ecpg_process_output on line %d: asynchronous notification of \"%s\" from backend PID %d received\n",
17291729
stmt->lineno,notify->relname,notify->be_pid);
17301730
PQfreemem(notify);
1731+
PQconsumeInput(stmt->connection->connection);
17311732
}
17321733

17331734
returnstatus;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2265,6 +2265,9 @@ PQsendDescribe(PGconn *conn, char desc_type, const char *desc_target)
22652265
* no unhandled async notification from the backend
22662266
*
22672267
* the CALLER is responsible for FREE'ing the structure returned
2268+
*
2269+
* Note that this function does not read any new data from the socket;
2270+
* so usually, caller should call PQconsumeInput() first.
22682271
*/
22692272
PGnotify*
22702273
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