diff options
author | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2019-10-16 14:51:34 +0200 |
---|---|---|
committer | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2019-10-16 14:51:34 +0200 |
commit | 0d21f919eb86cd3baa267844d111c6a5af480696 (patch) | |
tree | cd33ac1ba1b2afb06bd1be04540f9d1d3c028424 /src/backend/commands/indexcmds.c | |
parent | a524f50d0fc6fe6f2146ce708c2c9576d3734da4 (diff) | |
download | postgresql-0d21f919eb86cd3baa267844d111c6a5af480696.tar.gz postgresql-0d21f919eb86cd3baa267844d111c6a5af480696.zip |
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 ab0dfc961b6a, so backpatch to pg12.
Reported by: Justin Pryzby
Reviewed-by: Michaƫl Paquier
Discussion: https://postgr.es/m/20191012004446.GT10470@telsasoft.com
Diffstat (limited to 'src/backend/commands/indexcmds.c')
-rw-r--r-- | src/backend/commands/indexcmds.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 70f9b6729a7..589b8816a4d 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -384,12 +384,14 @@ WaitForOlderSnapshots(TransactionId limitXmin, bool progress) if (VirtualTransactionIdIsValid(old_snapshots[i])) { + /* If requested, publish who we're going to wait for. */ if (progress) { PGPROC *holder = BackendIdGetProc(old_snapshots[i].backendId); - pgstat_progress_update_param(PROGRESS_WAITFOR_CURRENT_PID, - holder->pid); + if (holder) + pgstat_progress_update_param(PROGRESS_WAITFOR_CURRENT_PID, + holder->pid); } VirtualXactLock(old_snapshots[i], true); } |