summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2020-09-04 20:20:05 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2020-09-04 20:33:37 -0400
commit9b81a30f924cf30e6bf3abb3366706440351e163 (patch)
tree81fac1408fb62d45c38a40b40e3bb0fc665fb14d
parent4a4f3bf983b4abd908585a8d752eee0e47627034 (diff)
Fix over-eager ping'ing in logical replication receiver.
Commit 3f60f690f 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
-rw-r--r--src/backend/replication/logical/worker.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/src/backend/replication/logical/worker.c b/src/backend/replication/logical/worker.c
index 73b3837db66..fde4a254712 100644
--- a/src/backend/replication/logical/worker.c
+++ b/src/backend/replication/logical/worker.c
@@ -1491,6 +1491,7 @@ static void
LogicalRepApplyLoop(XLogRecPtr last_received)
{
TimestampTz last_recv_timestamp = GetCurrentTimestamp();
+ bool ping_sent = false;
/*
* Init the ApplyMessageContext which we clean up after each replication
@@ -1503,6 +1504,7 @@ LogicalRepApplyLoop(XLogRecPtr last_received)
/* mark as idle, before starting to loop */
pgstat_report_activity(STATE_IDLE, NULL);
+ /* This outer loop iterates once per wait. */
for (;;)
{
pgsocket fd = PGINVALID_SOCKET;
@@ -1510,7 +1512,6 @@ LogicalRepApplyLoop(XLogRecPtr last_received)
int len;
char *buf = NULL;
bool endofstream = false;
- bool ping_sent = false;
long wait_time;
CHECK_FOR_INTERRUPTS();
@@ -1521,7 +1522,7 @@ LogicalRepApplyLoop(XLogRecPtr last_received)
if (len != 0)
{
- /* Process the data */
+ /* Loop to process all available data (without blocking). */
for (;;)
{
CHECK_FOR_INTERRUPTS();
@@ -1690,10 +1691,7 @@ LogicalRepApplyLoop(XLogRecPtr last_received)
ereport(ERROR,
(errmsg("terminating logical replication worker due to timeout")));
- /*
- * We didn't receive anything new, for half of receiver
- * replication timeout. Ping the server.
- */
+ /* Check to see if it's time for a ping. */
if (!ping_sent)
{
timeout = TimestampTzPlusMilliseconds(last_recv_timestamp,