Skip to content

Commit 7156a0e

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 cb9d1fa commit 7156a0e

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
@@ -1145,6 +1145,7 @@ static void
11451145
LogicalRepApplyLoop(XLogRecPtr last_received)
11461146
{
11471147
TimestampTz last_recv_timestamp = GetCurrentTimestamp();
1148+
bool ping_sent = false;
11481149

11491150
/*
11501151
* Init the ApplyMessageContext which we clean up after each replication
@@ -1157,14 +1158,14 @@ LogicalRepApplyLoop(XLogRecPtr last_received)
11571158
/* mark as idle, before starting to loop */
11581159
pgstat_report_activity(STATE_IDLE, NULL);
11591160

1161+
/* This outer loop iterates once per wait. */
11601162
for (;;)
11611163
{
11621164
pgsocket fd = PGINVALID_SOCKET;
11631165
int rc;
11641166
int len;
11651167
char *buf = NULL;
11661168
bool endofstream = false;
1167-
bool ping_sent = false;
11681169
long wait_time;
11691170

11701171
CHECK_FOR_INTERRUPTS();
@@ -1175,7 +1176,7 @@ LogicalRepApplyLoop(XLogRecPtr last_received)
11751176

11761177
if (len != 0)
11771178
{
1178-
/* Process the data */
1179+
/* Loop to process all available data (without blocking). */
11791180
for (;;)
11801181
{
11811182
CHECK_FOR_INTERRUPTS();
@@ -1348,10 +1349,7 @@ LogicalRepApplyLoop(XLogRecPtr last_received)
13481349
ereport(ERROR,
13491350
(errmsg("terminating logical replication worker due to timeout")));
13501351

1351-
/*
1352-
* We didn't receive anything new, for half of receiver
1353-
* replication timeout. Ping the server.
1354-
*/
1352+
/* Check to see if it's time for a ping. */
13551353
if (!ping_sent)
13561354
{
13571355
timeout = TimestampTzPlusMilliseconds(last_recv_timestamp,

0 commit comments

Comments
 (0)