Skip to content

Commit 9b81a30

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 4a4f3bf commit 9b81a30

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
@@ -1491,6 +1491,7 @@ static void
14911491
LogicalRepApplyLoop(XLogRecPtr last_received)
14921492
{
14931493
TimestampTz last_recv_timestamp = GetCurrentTimestamp();
1494+
bool ping_sent = false;
14941495

14951496
/*
14961497
* Init the ApplyMessageContext which we clean up after each replication
@@ -1503,14 +1504,14 @@ LogicalRepApplyLoop(XLogRecPtr last_received)
15031504
/* mark as idle, before starting to loop */
15041505
pgstat_report_activity(STATE_IDLE, NULL);
15051506

1507+
/* This outer loop iterates once per wait. */
15061508
for (;;)
15071509
{
15081510
pgsocket fd = PGINVALID_SOCKET;
15091511
int rc;
15101512
int len;
15111513
char *buf = NULL;
15121514
bool endofstream = false;
1513-
bool ping_sent = false;
15141515
long wait_time;
15151516

15161517
CHECK_FOR_INTERRUPTS();
@@ -1521,7 +1522,7 @@ LogicalRepApplyLoop(XLogRecPtr last_received)
15211522

15221523
if (len != 0)
15231524
{
1524-
/* Process the data */
1525+
/* Loop to process all available data (without blocking). */
15251526
for (;;)
15261527
{
15271528
CHECK_FOR_INTERRUPTS();
@@ -1690,10 +1691,7 @@ LogicalRepApplyLoop(XLogRecPtr last_received)
16901691
ereport(ERROR,
16911692
(errmsg("terminating logical replication worker due to timeout")));
16921693

1693-
/*
1694-
* We didn't receive anything new, for half of receiver
1695-
* replication timeout. Ping the server.
1696-
*/
1694+
/* Check to see if it's time for a ping. */
16971695
if (!ping_sent)
16981696
{
16991697
timeout = TimestampTzPlusMilliseconds(last_recv_timestamp,

0 commit comments

Comments
 (0)