From: Daniel Gustafsson Date: Sun, 5 Apr 2026 23:55:06 +0000 (+0200) Subject: Handle checksumworker startup wait race X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d771b0a907e67dc929dbbdebf70ecb006081b629;p=thirdparty%2Fpostgresql.git Handle checksumworker startup wait race If the background worker for processing databases manages to finish before the launcher starts waiting for it, the launcher would treat it erroneously as an error. Fix by ensureing to check result state in this case. Identified on CI and synthetically reproduced during local testing. Also while, make sure to properly lock the shared memory structure before updating tje result state. Author: Daniel Gustafsson Discussion: https://postgr.es/m/4fxw37ge47v5baeozla5phymi233hxbcjbwwsfwv3mpg3kyl2z@6jk4nkf6jp4 --- diff --git a/src/backend/postmaster/datachecksum_state.c b/src/backend/postmaster/datachecksum_state.c index eb7b01d0993..430e6e9a3c9 100644 --- a/src/backend/postmaster/datachecksum_state.c +++ b/src/backend/postmaster/datachecksum_state.c @@ -797,6 +797,19 @@ ProcessDatabase(DataChecksumsWorkerDatabase *db) status = WaitForBackgroundWorkerStartup(bgw_handle, &pid); if (status == BGWH_STOPPED) { + /* + * If the worker managed to start, and stop, before we got to waiting + * for it we can se a STOPPED status here without it being a failure. + */ + if (DataChecksumState->success == DATACHECKSUMSWORKER_SUCCESSFUL) + { + pgstat_report_activity(STATE_IDLE, NULL); + LWLockAcquire(DataChecksumsWorkerLock, LW_EXCLUSIVE); + DataChecksumState->worker_pid = InvalidPid; + LWLockRelease(DataChecksumsWorkerLock); + return DataChecksumState->success; + } + ereport(WARNING, errmsg("could not start background worker for enabling data checksums in database \"%s\"", db->dbname), @@ -1595,5 +1608,7 @@ DataChecksumsWorkerMain(Datum arg) /* worker done */ pgstat_progress_end_command(); + LWLockAcquire(DataChecksumsWorkerLock, LW_EXCLUSIVE); DataChecksumState->success = DATACHECKSUMSWORKER_SUCCESSFUL; + LWLockRelease(DataChecksumsWorkerLock); }