In particular I've seen an issue in the wild where idle_in_transaction_session_timeout did not get triggered because the HOLD_CANCEL_INTERRUPTS() in SocketBackend wraps around a pq_getbyte() call, and so ProcessInterrupts doesn't do anything when it gets called because the query cancel holdoff counter is positive.
Andres suggested the following re-ordering of the logic on -bugs:
On Wed, Sep 20, 2017 at 6:29 PM, Andres Freund <andres@anarazel.de> wrote:
if (QueryCancelPending && QueryCancelHoldoffCount != 0) { /* rearm */ } else if (QueryCancelPending) { /* handle interrupt */ }
Which is implemented in the attached patch.
Unless someone wants to pick this up right away, I'll register it in the next commitfest tomorrow.