diff --git a/src/gausskernel/storage/replication/walsender.cpp b/src/gausskernel/storage/replication/walsender.cpp index 00ccb652b..4c937c17f 100755 --- a/src/gausskernel/storage/replication/walsender.cpp +++ b/src/gausskernel/storage/replication/walsender.cpp @@ -2030,7 +2030,6 @@ static XLogRecPtr WalSndWaitForWal(XLogRecPtr loc) if (XLByteLT(t_thrd.walsender_cxt.MyWalSnd->flush, t_thrd.walsender_cxt.sentPtr) && !t_thrd.walsender_cxt.waiting_for_ping_response) { WalSndKeepalive(false); - t_thrd.walsender_cxt.waiting_for_ping_response = true; } } @@ -6375,9 +6374,12 @@ Datum pg_stat_get_wal_senders(PG_FUNCTION_ARGS) } /* - * This function is used to send keepalive message to standby. - * If requestReply is set, sets a flag in the message requesting the standby - * to send a message back to us, for heartbeat purposes. + * Send a keepalive message to standby. + * + * If requestReply is set, the message requests the other party to send + * a message back to us, for heartbeat purposes. We also set a flag to + * let nearby code know that we're waiting for that response, to avoid + * repeated requests. */ static void WalSndKeepalive(bool requestReply) { @@ -6407,6 +6409,11 @@ static void WalSndKeepalive(bool requestReply) /* Flush the keepalive message to standby immediately. */ if (pq_flush_if_writable() != 0) WalSndShutdown(); + + /* Set local flag */ + if (requestReply) { + t_thrd.walsender_cxt.waiting_for_ping_response = true; + } } /* @@ -6491,7 +6498,6 @@ static void WalSndKeepaliveIfNecessary(TimestampTz now) ping_time = TimestampTzPlusMilliseconds(t_thrd.walsender_cxt.last_reply_timestamp, timeout / 2); if (now >= ping_time) { WalSndKeepalive(true); - t_thrd.walsender_cxt.waiting_for_ping_response = true; } }