Skip to content

Commit 9b47ee6

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 616110e commit 9b47ee6

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
@@ -1132,6 +1132,7 @@ static void
11321132
LogicalRepApplyLoop(XLogRecPtr last_received)
11331133
{
11341134
TimestampTz last_recv_timestamp = GetCurrentTimestamp();
1135+
bool ping_sent = false;
11351136

11361137
/*
11371138
* Init the ApplyMessageContext which we clean up after each replication
@@ -1144,14 +1145,14 @@ LogicalRepApplyLoop(XLogRecPtr last_received)
11441145
/* mark as idle, before starting to loop */
11451146
pgstat_report_activity(STATE_IDLE, NULL);
11461147

1148+
/* This outer loop iterates once per wait. */
11471149
for (;;)
11481150
{
11491151
pgsocket fd = PGINVALID_SOCKET;
11501152
int rc;
11511153
int len;
11521154
char *buf = NULL;
11531155
bool endofstream = false;
1154-
bool ping_sent = false;
11551156
long wait_time;
11561157

11571158
CHECK_FOR_INTERRUPTS();
@@ -1162,7 +1163,7 @@ LogicalRepApplyLoop(XLogRecPtr last_received)
11621163

11631164
if (len != 0)
11641165
{
1165-
/* Process the data */
1166+
/* Loop to process all available data (without blocking). */
11661167
for (;;)
11671168
{
11681169
CHECK_FOR_INTERRUPTS();
@@ -1331,10 +1332,7 @@ LogicalRepApplyLoop(XLogRecPtr last_received)
13311332
ereport(ERROR,
13321333
(errmsg("terminating logical replication worker due to timeout")));
13331334

1334-
/*
1335-
* We didn't receive anything new, for half of receiver
1336-
* replication timeout. Ping the server.
1337-
*/
1335+
/* Check to see if it's time for a ping. */
13381336
if (!ping_sent)
13391337
{
13401338
timeout = TimestampTzPlusMilliseconds(last_recv_timestamp,

0 commit comments

Comments
 (0)