Skip to content

Commit 9b8a851

Browse files
committed
Fix over-eager ping'ing in logical replication receiver.
Commit 3f60f69 only partially fixed the broken-status-tracking issue in LogicalRepApplyLoop: we need ping_sent to have the same lifetime as last_recv_timestamp. The effects are much less serious than what that commit fixed, though. AFAICS this would just lead to extra ping requests being sent, once per second until the sender responds. Still, it's a bug, so backpatch to v10 as before. Discussion: https://postgr.es/m/959627.1599248476@sss.pgh.pa.us
1 parent 63abf9a commit 9b8a851

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/backend/replication/logical/worker.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,7 @@ static void
10771077
LogicalRepApplyLoop(XLogRecPtr last_received)
10781078
{
10791079
TimestampTz last_recv_timestamp = GetCurrentTimestamp();
1080+
bool ping_sent = false;
10801081

10811082
/*
10821083
* Init the ApplyMessageContext which we clean up after each replication
@@ -1089,14 +1090,14 @@ LogicalRepApplyLoop(XLogRecPtr last_received)
10891090
/* mark as idle, before starting to loop */
10901091
pgstat_report_activity(STATE_IDLE, NULL);
10911092

1093+
/* This outer loop iterates once per wait. */
10921094
for (;;)
10931095
{
10941096
pgsocket fd = PGINVALID_SOCKET;
10951097
int rc;
10961098
int len;
10971099
char *buf = NULL;
10981100
bool endofstream = false;
1099-
bool ping_sent = false;
11001101
long wait_time;
11011102

11021103
CHECK_FOR_INTERRUPTS();
@@ -1107,7 +1108,7 @@ LogicalRepApplyLoop(XLogRecPtr last_received)
11071108

11081109
if (len != 0)
11091110
{
1110-
/* Process the data */
1111+
/* Loop to process all available data (without blocking). */
11111112
for (;;)
11121113
{
11131114
CHECK_FOR_INTERRUPTS();
@@ -1280,10 +1281,7 @@ LogicalRepApplyLoop(XLogRecPtr last_received)
12801281
ereport(ERROR,
12811282
(errmsg("terminating logical replication worker due to timeout")));
12821283

1283-
/*
1284-
* We didn't receive anything new, for half of receiver
1285-
* replication timeout. Ping the server.
1286-
*/
1284+
/* Check to see if it's time for a ping. */
12871285
if (!ping_sent)
12881286
{
12891287
timeout = TimestampTzPlusMilliseconds(last_recv_timestamp,

0 commit comments

Comments
 (0)