Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kEHaK-00078J-CE for pgsql-hackers@arkaria.postgresql.org; Fri, 04 Sep 2020 19:41:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kEHaJ-0000OM-Ax for pgsql-hackers@arkaria.postgresql.org; Fri, 04 Sep 2020 19:41:19 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kEHaJ-0000OE-3x for pgsql-hackers@lists.postgresql.org; Fri, 04 Sep 2020 19:41:19 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kEHaH-0006nu-0I for pgsql-hackers@lists.postgresql.org; Fri, 04 Sep 2020 19:41:18 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 084JfG3s959628 for ; Fri, 4 Sep 2020 15:41:16 -0400 From: Tom Lane To: pgsql-hackers@lists.postgresql.org Subject: Questionable ping logic in LogicalRepApplyLoop MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <959626.1599248476.1@sss.pgh.pa.us> Date: Fri, 04 Sep 2020 15:41:16 -0400 Message-ID: <959627.1599248476@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk While playing around with clang's scan-build I noticed this warning: worker.c:2281:7: warning: Value stored to 'ping_sent' is never read ping_sent = true; ^ ~~~~ At first I thought it was a harmless unnecessary update, but looking closer I wonder whether it isn't telling us there is a logic bug here. Specifically, I wonder why the "ping_sent" variable is local to the loop starting at line 2084, rather than having the same lifespan as "last_recv_timestamp". Do we really want to forget that we sent a ping anytime we have to wait for more data? In fact, looking closer, it appears to me that (1) The "ping_sent = false" at line 2124 is also dead code, because ping_sent could never be anything but false at this point; (2) The "if (!ping_sent)" at line 2274 is also dead code, because ping_sent is still never anything but false at that point. In short, we could remove the ping_sent variable entirely without changing this code's behavior. I'm not 100% sure what semantics it's trying to achieve, but I don't think it's achieving them. regards, tom lane