fix archive module shutdown callback - Mailing list pgsql-hackers

From Nathan Bossart
Subject fix archive module shutdown callback
Date
Msg-id 20221015221328.GB1821022@nathanxps13
Whole thread Raw
Responses Re: fix archive module shutdown callback  (Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>)
List pgsql-hackers
Hi hackers,

Presently, when an archive module sets up a shutdown callback, it will be
called upon ERROR/FATAL (via PG_ENSURE_ERROR_CLEANUP), when the archive
library changes (via HandlePgArchInterrupts()), and upon normal shutdown.
There are a couple of problems with this:

* HandlePgArchInterrupts() calls the shutdown callback directly before
proc_exit().  However, the PG_ENSURE_ERROR_CLEANUP surrounding the call to
pgarch_MainLoop() sets up a before_shmem_exit callback that also calls the
shutdown callback.  This means that the shutdown callback will be called
twice whenever archive_library is changed via SIGHUP.

* PG_ENSURE_ERROR_CLEANUP is intended for both ERROR and FATAL.  However,
the archiver operates at the bottom of the exception stack, so ERRORs are
treated as FATALs.  This means that PG_ENSURE_ERROR_CLEANUP is excessive.
We only need to set up the before_shmem_exit callback.

To fix, the attached patch removes the use of PG_ENSURE_ERROR_CLEANUP and
the call to the shutdown callback in HandlePgArchInterrupts() in favor of
just setting up a before_shmem_exit callback in LoadArchiveLibrary().

-- 
Nathan Bossart
Amazon Web Services: https://aws.amazon.com

Attachment

pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: macos ventura SDK spews warnings
Next
From: Tom Lane
Date:
Subject: Re: macos ventura SDK spews warnings