Skip to content

Commit f10da1e

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 348dd28 commit f10da1e

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

14411441
last_processing = GetCurrentTimestamp();
14421442

1443-
for (;;)
1443+
/*
1444+
* If we already received a CopyDone from the frontend, any subsequent
1445+
* message is the beginning of a new command, and should be processed in
1446+
* the main processing loop.
1447+
*/
1448+
while (!streamingDoneReceiving)
14441449
{
14451450
pq_startmsgread();
14461451
r = pq_getbyte_if_available(&firstchar);
@@ -1469,19 +1474,6 @@ ProcessRepliesIfAny(void)
14691474
proc_exit(0);
14701475
}
14711476

1472-
/*
1473-
* If we already received a CopyDone from the frontend, the frontend
1474-
* should not send us anything until we've closed our end of the COPY.
1475-
* XXX: In theory, the frontend could already send the next command
1476-
* before receiving the CopyDone, but libpq doesn't currently allow
1477-
* that.
1478-
*/
1479-
if (streamingDoneReceiving && firstchar != 'X')
1480-
ereport(FATAL,
1481-
(errcode(ERRCODE_PROTOCOL_VIOLATION),
1482-
errmsg("unexpected standby message type \"%c\", after receiving CopyDone",
1483-
firstchar)));
1484-
14851477
/* Handle the very limited subset of commands expected in this phase */
14861478
switch (firstchar)
14871479
{
@@ -1963,8 +1955,10 @@ WalSndLoop(WalSndSendDataCallback send_data)
19631955
long sleeptime;
19641956
int wakeEvents;
19651957

1966-
wakeEvents = WL_LATCH_SET | WL_POSTMASTER_DEATH | WL_TIMEOUT |
1967-
WL_SOCKET_READABLE;
1958+
wakeEvents = WL_LATCH_SET | WL_POSTMASTER_DEATH | WL_TIMEOUT;
1959+
1960+
if (!streamingDoneReceiving)
1961+
wakeEvents |= WL_SOCKET_READABLE;
19681962

19691963
/*
19701964
* Use fresh timestamp, not last_processed, to reduce the chance

0 commit comments

Comments
 (0)