Questionable ping logic in LogicalRepApplyLoop

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Questionable ping logic in LogicalRepApplyLoop
Date: 2020-09-04 19:41:16
Message-ID: 959627.1599248476@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message David G. Johnston 2020-09-04 19:45:36 Re: BUG #16419: wrong parsing BC year in to_date() function
Previous Message Alvaro Herrera 2020-09-04 19:38:32 Re: Concurrent failure in create_am with buildfarm member conchuela