Fix timeout handling in logical replication worker
authorMichael Paquier <[email protected]>
Fri, 18 Oct 2019 05:27:04 +0000 (14:27 +0900)
committerMichael Paquier <[email protected]>
Fri, 18 Oct 2019 05:27:04 +0000 (14:27 +0900)
The timestamp tracking the last moment a message is received in a
logical replication worker was initialized in each loop checking if a
message was received or not, causing wal_receiver_timeout to be ignored
in basically any logical replication deployments.  This also broke the
ping sent to the server when reaching half of wal_receiver_timeout.

This simply moves the initialization of the timestamp out of the apply
loop to the beginning of LogicalRepApplyLoop().

Reported-by: Jehan-Guillaume De Rorthais
Author: Julien Rouhaud
Discussion: https://postgr.es/m/CAOBaU_ZHESFcWva8jLjtZdCLspMj7vqaB2k++rjHLY897ZxbYw@mail.gmail.com
Backpatch-through: 10

src/backend/replication/logical/worker.c

index bd600945761b15a1c343277efdc4b56e546025fe..737c40c1e72726b792a880202339062f96ef4276 100644 (file)
@@ -1035,6 +1035,8 @@ UpdateWorkerStats(XLogRecPtr last_lsn, TimestampTz send_time, bool reply)
 static void
 LogicalRepApplyLoop(XLogRecPtr last_received)
 {
+   TimestampTz last_recv_timestamp = GetCurrentTimestamp();
+
    /*
     * Init the ApplyMessageContext which we clean up after each replication
     * protocol message.
@@ -1053,7 +1055,6 @@ LogicalRepApplyLoop(XLogRecPtr last_received)
        int         len;
        char       *buf = NULL;
        bool        endofstream = false;
-       TimestampTz last_recv_timestamp = GetCurrentTimestamp();
        bool        ping_sent = false;
        long        wait_time;