Do we want to solve reload/config races more generally? (was: Postmaster crashes on SIGHUP when oauth_validator_libraries holds only whitespace)
Do we want to solve reload/config races more generally? (was: Postmaster crashes on SIGHUP when oauth_validator_libraries holds only whitespace)
От:
Jacob Champion <jacob.champion@enterprisedb.com>
Дата:
On Wed, Sep 30, 2026 at 11:20 AM Jacob Champion
wrote:
> On Wed, Sep 30, 2026 at 11:00 AM Alexander Lakhin wrote:
> > The test addition coined with bca67e5a3 is not very robust,
> > unfortunately. Buildfarm animal serinus found a way to break it [1]
> > as below:
>
> Bleh. These SIGHUP/log file races are really annoying, and I'm going
> to need to trawl the list to see if anyone's proposed a more general
> solution. (I keep thinking about assigning an xid as a generation
> number to an in-memory configuration...)
Moving over to -hackers in case anyone has thoughts. I notice [1]
touched on a similar thing, only with pg_ident/hba.
The general issue, for anyone new to the problem, is that reloading
doesn't wait for the effects of the SIGHUP to complete. (And the
meaning of "complete" depends on the test case.) It feels like this
would pop up in more situations, but the buildfarm doesn't always show
it and it's an easy trap to fall into.
Outside of development, it really seems like a DBA would like to say
"I reloaded the server using and it succeeded, so now I
_know_ that my changes have been applied."
> For now, is the following test giving us much, or can we remove it?
> We've already done the wait_for_log(). If that "sequence point" turns
> out to be inadequate for some other reason, we'd have to fix it
> anyway.
>
> > is($bgconn->query_safe('SHOW oauth_validator_libraries'),
> > 'validator', 'oauth_validator_libraries restored');
I just pushed a commit removing this check. (We don't need the $bgconn
backend to reflect the current state. We only care that _new_ backends
will adopt the new setting.)
Thanks,
--Jacob
[1] https://postgr.es/m/CAJTYsWWGXJRhefkYs6wZFUOHqE9k5VSoABH2uzke5FMBSmE0%3Dw%40mail.gmail.com
Re: Do we want to solve reload/config races more generally? (was: Postmaster crashes on SIGHUP when oauth_validator_libraries holds only whitespace)
От:
Andrey Borodin <x4mmm@yandex-team.ru>
Дата:
> On 8 Oct 2026, at 23:28, Jacob Champion wrote: > > The general issue, for anyone new to the problem, is that reloading > doesn't wait for the effects of the SIGHUP to complete. (And the > meaning of "complete" depends on the test case.) It feels like this > would pop up in more situations, but the buildfarm doesn't always show > it and it's an easy trap to fall into. Few days ago maintainers of pgconsul (HA tool) asked me: how to wait until synchronous_stanby_names takes effect? For some reason they need to commit one transaction with full quorum. The best solution we found was to restart the node and insert\commit afterwards. So yeah, +1 for having synchronous reload. Best regards, Andrey Borodin.
Re: Do we want to solve reload/config races more generally? (was: Postmaster crashes on SIGHUP when oauth_validator_libraries holds only whitespace)
От:
Jacob Champion <jacob.champion@enterprisedb.com>
Дата:
On Thu, Oct 8, 2026 at 11:53 AM Andrey Borodin wrote:
> Few days ago maintainers of pgconsul (HA tool) asked me: how to wait until
> synchronous_stanby_names takes effect? For some reason they need to commit one
> transaction with full quorum. The best solution we found was to restart the node
> and insert\commit afterwards.
Our tests tend to restart to get around this problem, too, and that's
really heavyweight.
The oauth_validator test suite waits for lines in the logs to avoid
the restart penalty. But strictly speaking, it's waiting for the
*wrong* log line ("received SIGHUP, reloading configuration files").
That only works because the postmaster isn't multithreaded, and
knowing that the postmaster has started processing the SIGHUP is
enough to know that the next connection will pick up the new setting.
But I'm not really confident that all the happens-before logic shakes
out correctly in every corner case.
> So yeah, +1 for having synchronous reload.
What are the things we'd need to support for this to make sense as a
feature? I could see use cases for
- wait until new connections are guaranteed to see the new configuration
- wait until *all* backends are
We would need to deal with concurrent changes/reloads correctly. Like,
I imagine no one's going to immediately demand "serializable
isolation", since the current architecture provides very few
guarantees, but it needs to make intuitive sense... If you make a
configuration change, and then sync-reload, you should see the result
of either your change or a change that came afterwards.
Thanks,
--Jacob
Re: Do we want to solve reload/config races more generally? (was: Postmaster crashes on SIGHUP when oauth_validator_libraries holds only whitespace)
От:
Andrey Borodin <x4mmm@yandex-team.ru>
Дата:
On 8 Oct 2026, Jacob Champion wrote: > - wait until *all* backends are A synchronous reload that guarantees the new configuration for subsequent connections would already be useful. My synchronous_standby_names example needs more: walsenders and the checkpointer also update shared sync-rep state after ProcessConfigFile(). Acknowledging completion inside that function would be too early. Building on your generation idea, could we number reload requests and acknowledge the number captured before reading the files? A request arriving during a reload must not be satisfied by completion of that older reload. We'd also need to distinguish completion from successful application. For testing, I posted a patch for filesystem-controlled wait injection points in pgsql-bugs [0]. A waiting process publishes a PID file; TAP can observe it and release the process by removing that file, without SQL. With points around a backend's reload, we could hold it back while the postmaster finishes, then test the two guarantees separately. The posted series uses this to coordinate startup during crash recovery. Thank you! Best regards, Andrey Borodin. [0] https://www.postgresql.org/message-id/AE31E3B7-A21B-4C1C-B75B-8D542A9DC633%40yandex-team.ru
Re: Do we want to solve reload/config races more generally? (was: Postmaster crashes on SIGHUP when oauth_validator_libraries holds only whitespace)
Hello There's still a leftover empty validator issue, even if not that serious: '""'. It returns a list with a single empty string, so the new check doesn't catch it, the hba line gets a single empty named validator. This hits an assertion in debug builds, but otherwise works mostly fine in release builds with a 'could not access file ""' error. The attached patch adds an additional check for this.