Skip to content

Commit a58db3a

Browse files
committed
Revert "Cannot use WL_SOCKET_WRITEABLE without WL_SOCKET_READABLE."
This reverts commit 3a9e64a. Commit 4bad60e fixed the root of the problem that 3a9e64a worked around. This enables proper pipelining of commands after terminating replication, eliminating an undocumented limitation. Discussion: https://postgr.es/m/3d57bc29-4459-578b-79cb-7641baf53c57%40iki.fi Backpatch-through: 9.5
1 parent 9b58495 commit a58db3a

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

src/backend/replication/walsender.c

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1719,7 +1719,12 @@ ProcessRepliesIfAny(void)
17191719

17201720
last_processing = GetCurrentTimestamp();
17211721

1722-
for (;;)
1722+
/*
1723+
* If we already received a CopyDone from the frontend, any subsequent
1724+
* message is the beginning of a new command, and should be processed in
1725+
* the main processing loop.
1726+
*/
1727+
while (!streamingDoneReceiving)
17231728
{
17241729
pq_startmsgread();
17251730
r = pq_getbyte_if_available(&firstchar);
@@ -1748,19 +1753,6 @@ ProcessRepliesIfAny(void)
17481753
proc_exit(0);
17491754
}
17501755

1751-
/*
1752-
* If we already received a CopyDone from the frontend, the frontend
1753-
* should not send us anything until we've closed our end of the COPY.
1754-
* XXX: In theory, the frontend could already send the next command
1755-
* before receiving the CopyDone, but libpq doesn't currently allow
1756-
* that.
1757-
*/
1758-
if (streamingDoneReceiving && firstchar != 'X')
1759-
ereport(FATAL,
1760-
(errcode(ERRCODE_PROTOCOL_VIOLATION),
1761-
errmsg("unexpected standby message type \"%c\", after receiving CopyDone",
1762-
firstchar)));
1763-
17641756
/* Handle the very limited subset of commands expected in this phase */
17651757
switch (firstchar)
17661758
{
@@ -2362,8 +2354,10 @@ WalSndLoop(WalSndSendDataCallback send_data)
23622354
long sleeptime;
23632355
int wakeEvents;
23642356

2365-
wakeEvents = WL_LATCH_SET | WL_EXIT_ON_PM_DEATH | WL_TIMEOUT |
2366-
WL_SOCKET_READABLE;
2357+
wakeEvents = WL_LATCH_SET | WL_EXIT_ON_PM_DEATH | WL_TIMEOUT;
2358+
2359+
if (!streamingDoneReceiving)
2360+
wakeEvents |= WL_SOCKET_READABLE;
23672361

23682362
/*
23692363
* Use fresh timestamp, not last_processing, to reduce the chance

0 commit comments

Comments
 (0)