Commit c8746f99 authored by Tom Lane's avatar Tom Lane

Fix over-eager ping'ing in logical replication receiver.

Commit 3f60f690 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
parent 9a851039
...@@ -2060,6 +2060,7 @@ static void ...@@ -2060,6 +2060,7 @@ static void
LogicalRepApplyLoop(XLogRecPtr last_received) LogicalRepApplyLoop(XLogRecPtr last_received)
{ {
TimestampTz last_recv_timestamp = GetCurrentTimestamp(); TimestampTz last_recv_timestamp = GetCurrentTimestamp();
bool ping_sent = false;
/* /*
* Init the ApplyMessageContext which we clean up after each replication * Init the ApplyMessageContext which we clean up after each replication
...@@ -2080,6 +2081,7 @@ LogicalRepApplyLoop(XLogRecPtr last_received) ...@@ -2080,6 +2081,7 @@ LogicalRepApplyLoop(XLogRecPtr last_received)
/* mark as idle, before starting to loop */ /* mark as idle, before starting to loop */
pgstat_report_activity(STATE_IDLE, NULL); pgstat_report_activity(STATE_IDLE, NULL);
/* This outer loop iterates once per wait. */
for (;;) for (;;)
{ {
pgsocket fd = PGINVALID_SOCKET; pgsocket fd = PGINVALID_SOCKET;
...@@ -2087,7 +2089,6 @@ LogicalRepApplyLoop(XLogRecPtr last_received) ...@@ -2087,7 +2089,6 @@ LogicalRepApplyLoop(XLogRecPtr last_received)
int len; int len;
char *buf = NULL; char *buf = NULL;
bool endofstream = false; bool endofstream = false;
bool ping_sent = false;
long wait_time; long wait_time;
CHECK_FOR_INTERRUPTS(); CHECK_FOR_INTERRUPTS();
...@@ -2098,7 +2099,7 @@ LogicalRepApplyLoop(XLogRecPtr last_received) ...@@ -2098,7 +2099,7 @@ LogicalRepApplyLoop(XLogRecPtr last_received)
if (len != 0) if (len != 0)
{ {
/* Process the data */ /* Loop to process all available data (without blocking). */
for (;;) for (;;)
{ {
CHECK_FOR_INTERRUPTS(); CHECK_FOR_INTERRUPTS();
...@@ -2267,10 +2268,7 @@ LogicalRepApplyLoop(XLogRecPtr last_received) ...@@ -2267,10 +2268,7 @@ LogicalRepApplyLoop(XLogRecPtr last_received)
ereport(ERROR, ereport(ERROR,
(errmsg("terminating logical replication worker due to timeout"))); (errmsg("terminating logical replication worker due to timeout")));
/* /* Check to see if it's time for a ping. */
* We didn't receive anything new, for half of receiver
* replication timeout. Ping the server.
*/
if (!ping_sent) if (!ping_sent)
{ {
timeout = TimestampTzPlusMilliseconds(last_recv_timestamp, timeout = TimestampTzPlusMilliseconds(last_recv_timestamp,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment