Skip to content

Commit 133a090

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 da21424 commit 133a090

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
@@ -1434,7 +1434,12 @@ ProcessRepliesIfAny(void)
14341434

14351435
last_processing = GetCurrentTimestamp();
14361436

1437-
for (;;)
1437+
/*
1438+
* If we already received a CopyDone from the frontend, any subsequent
1439+
* message is the beginning of a new command, and should be processed in
1440+
* the main processing loop.
1441+
*/
1442+
while (!streamingDoneReceiving)
14381443
{
14391444
pq_startmsgread();
14401445
r = pq_getbyte_if_available(&firstchar);
@@ -1463,19 +1468,6 @@ ProcessRepliesIfAny(void)
14631468
proc_exit(0);
14641469
}
14651470

1466-
/*
1467-
* If we already received a CopyDone from the frontend, the frontend
1468-
* should not send us anything until we've closed our end of the COPY.
1469-
* XXX: In theory, the frontend could already send the next command
1470-
* before receiving the CopyDone, but libpq doesn't currently allow
1471-
* that.
1472-
*/
1473-
if (streamingDoneReceiving && firstchar != 'X')
1474-
ereport(FATAL,
1475-
(errcode(ERRCODE_PROTOCOL_VIOLATION),
1476-
errmsg("unexpected standby message type \"%c\", after receiving CopyDone",
1477-
firstchar)));
1478-
14791471
/* Handle the very limited subset of commands expected in this phase */
14801472
switch (firstchar)
14811473
{
@@ -1960,8 +1952,10 @@ WalSndLoop(WalSndSendDataCallback send_data)
19601952
long sleeptime;
19611953
int wakeEvents;
19621954

1963-
wakeEvents = WL_LATCH_SET | WL_POSTMASTER_DEATH | WL_TIMEOUT |
1964-
WL_SOCKET_READABLE;
1955+
wakeEvents = WL_LATCH_SET | WL_POSTMASTER_DEATH | WL_TIMEOUT;
1956+
1957+
if (!streamingDoneReceiving)
1958+
wakeEvents |= WL_SOCKET_READABLE;
19651959

19661960
/*
19671961
* Use fresh timestamp, not last_processed, to reduce the chance

0 commit comments

Comments
 (0)