Reading over this code, I noticed that the detection of the catch-up state ends up being duplicate code, so I would rework that function as in the attached patch.
The naming of those flags (got_SIGUSR2, got_STOPPING) is terrible, but I'm not going to change that in a backpatchable bug fix.
Hi Alvaro, does this count as a review? And Craig, do you agree with Alvaro's patch as a replacement for your own?