Skip to content

Commit 0d21f91

Browse files
committed
Fix crash when reporting CREATE INDEX progress
A race condition can make us try to dereference a NULL pointer to the PGPROC struct of a process that's already finished. That results in crashes during REINDEX CONCURRENTLY and CREATE INDEX CONCURRENTLY. This was introduced in ab0dfc9, so backpatch to pg12. Reported by: Justin Pryzby Reviewed-by: Michaël Paquier Discussion: https://postgr.es/m/20191012004446.GT10470@telsasoft.com
1 parent a524f50 commit 0d21f91

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/backend/commands/indexcmds.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,12 +384,14 @@ WaitForOlderSnapshots(TransactionId limitXmin, bool progress)
384384

385385
if (VirtualTransactionIdIsValid(old_snapshots[i]))
386386
{
387+
/* If requested, publish who we're going to wait for. */
387388
if (progress)
388389
{
389390
PGPROC *holder = BackendIdGetProc(old_snapshots[i].backendId);
390391

391-
pgstat_progress_update_param(PROGRESS_WAITFOR_CURRENT_PID,
392-
holder->pid);
392+
if (holder)
393+
pgstat_progress_update_param(PROGRESS_WAITFOR_CURRENT_PID,
394+
holder->pid);
393395
}
394396
VirtualXactLock(old_snapshots[i], true);
395397
}

src/backend/storage/lmgr/lmgr.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -900,16 +900,14 @@ WaitForLockersMultiple(List *locktags, LOCKMODE lockmode, bool progress)
900900

901901
while (VirtualTransactionIdIsValid(*lockholders))
902902
{
903-
/*
904-
* If requested, publish who we're going to wait for. This is not
905-
* 100% accurate if they're already gone, but we don't care.
906-
*/
903+
/* If requested, publish who we're going to wait for. */
907904
if (progress)
908905
{
909906
PGPROC *holder = BackendIdGetProc(lockholders->backendId);
910907

911-
pgstat_progress_update_param(PROGRESS_WAITFOR_CURRENT_PID,
912-
holder->pid);
908+
if (holder)
909+
pgstat_progress_update_param(PROGRESS_WAITFOR_CURRENT_PID,
910+
holder->pid);
913911
}
914912
VirtualXactLock(*lockholders, true);
915913
lockholders++;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy