Skip to content

Commit c8746f9

Browse files
committedSep 5, 2020
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 9a85103 commit c8746f9

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed
 

‎src/backend/replication/logical/worker.c

+4-6
Original file line numberDiff line numberDiff line change
@@ -2060,6 +2060,7 @@ static void
20602060
LogicalRepApplyLoop(XLogRecPtr last_received)
20612061
{
20622062
TimestampTz last_recv_timestamp = GetCurrentTimestamp();
2063+
bool ping_sent = false;
20632064

20642065
/*
20652066
* Init the ApplyMessageContext which we clean up after each replication
@@ -2080,14 +2081,14 @@ LogicalRepApplyLoop(XLogRecPtr last_received)
20802081
/* mark as idle, before starting to loop */
20812082
pgstat_report_activity(STATE_IDLE, NULL);
20822083

2084+
/* This outer loop iterates once per wait. */
20832085
for (;;)
20842086
{
20852087
pgsocket fd = PGINVALID_SOCKET;
20862088
int rc;
20872089
int len;
20882090
char *buf = NULL;
20892091
bool endofstream = false;
2090-
bool ping_sent = false;
20912092
long wait_time;
20922093

20932094
CHECK_FOR_INTERRUPTS();
@@ -2098,7 +2099,7 @@ LogicalRepApplyLoop(XLogRecPtr last_received)
20982099

20992100
if (len != 0)
21002101
{
2101-
/* Process the data */
2102+
/* Loop to process all available data (without blocking). */
21022103
for (;;)
21032104
{
21042105
CHECK_FOR_INTERRUPTS();
@@ -2267,10 +2268,7 @@ LogicalRepApplyLoop(XLogRecPtr last_received)
22672268
ereport(ERROR,
22682269
(errmsg("terminating logical replication worker due to timeout")));
22692270

2270-
/*
2271-
* We didn't receive anything new, for half of receiver
2272-
* replication timeout. Ping the server.
2273-
*/
2271+
/* Check to see if it's time for a ping. */
22742272
if (!ping_sent)
22752273
{
22762274
timeout = TimestampTzPlusMilliseconds(last_recv_timestamp,

0 commit comments

Comments
 (0)