Fix background workers not restarting with restart_after_crash = on

From: Andrey Rudometov <unlimitedhikari(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Fix background workers not restarting with restart_after_crash = on
Date: 2025-06-11 08:26:01
Message-ID: CAF6JsWiO=i24qYitWe6ns1sXqcL86rYxdyU+pNYk-WueKPSySg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Good day, hackers.

Reading through changes committed in master, I noticed that after
CleanupBackend/CleanupBackroundworker refactor background workers will fail
to
start again after postgres' restart with restart_after_crash = on.

The reason is CleanupBackend and HandleChildCrash not setting background
worker's
rw_pid to zero anymore, if backend, well, crashed and failed to call
shmem_exit
and mark PMChild slot as inactive via MarkPostmasterChildInactive.

Suggested solution is to finish CleanupBackend's background worker related
logic
even after treating the child process as crashed. In earlier versions
zeroing of
pids happen in HandleChildCrash anyway, so there should be no harm in doing
the same actions here.

For fast reproduction I used pg_prewarm extension, as it creates observable
bgworker
and is present in postgres tree, so tap test is easy to run.
--
best regards,
Andrey Rudometov

Attachment Content-Type Size
v1-0001-Reproduce-bgw-not-starting-after-restart_after_cr.patch text/x-patch 6.3 KB
v1-0002-Fix-bgw-not-starting-after-restart_after_crash.patch text/x-patch 923 bytes

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2025-06-11 08:34:44 Re: Improve tab completion for various SET/RESET forms
Previous Message Xuneng Zhou 2025-06-11 07:58:26 Re: Proposal: Limitations of palloc inside checkpointer