Skip to content

Commit 4ee058a

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 970761f commit 4ee058a

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

16041604
last_processing = GetCurrentTimestamp();
16051605

1606-
for (;;)
1606+
/*
1607+
* If we already received a CopyDone from the frontend, any subsequent
1608+
* message is the beginning of a new command, and should be processed in
1609+
* the main processing loop.
1610+
*/
1611+
while (!streamingDoneReceiving)
16071612
{
16081613
pq_startmsgread();
16091614
r = pq_getbyte_if_available(&firstchar);
@@ -1632,19 +1637,6 @@ ProcessRepliesIfAny(void)
16321637
proc_exit(0);
16331638
}
16341639

1635-
/*
1636-
* If we already received a CopyDone from the frontend, the frontend
1637-
* should not send us anything until we've closed our end of the COPY.
1638-
* XXX: In theory, the frontend could already send the next command
1639-
* before receiving the CopyDone, but libpq doesn't currently allow
1640-
* that.
1641-
*/
1642-
if (streamingDoneReceiving && firstchar != 'X')
1643-
ereport(FATAL,
1644-
(errcode(ERRCODE_PROTOCOL_VIOLATION),
1645-
errmsg("unexpected standby message type \"%c\", after receiving CopyDone",
1646-
firstchar)));
1647-
16481640
/* Handle the very limited subset of commands expected in this phase */
16491641
switch (firstchar)
16501642
{
@@ -2212,8 +2204,10 @@ WalSndLoop(WalSndSendDataCallback send_data)
22122204
long sleeptime;
22132205
int wakeEvents;
22142206

2215-
wakeEvents = WL_LATCH_SET | WL_POSTMASTER_DEATH | WL_TIMEOUT |
2216-
WL_SOCKET_READABLE;
2207+
wakeEvents = WL_LATCH_SET | WL_POSTMASTER_DEATH | WL_TIMEOUT;
2208+
2209+
if (!streamingDoneReceiving)
2210+
wakeEvents |= WL_SOCKET_READABLE;
22172211

22182212
/*
22192213
* Use fresh timestamp, not last_processed, to reduce the chance

0 commit comments

Comments
 (0)