Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commiteeeb782

Browse files
committed
Fix a rare race condition when commit_siblings > 0 and a transaction commits
at the same instant as a new backend is spawned. Since CountActiveBackends()doesn't hold ProcArrayLock, it needs to be prepared for the case that apointer at the end of the proc array is still NULL even though numProcs saysit should be valid, since it doesn't hold ProcArrayLock. Backpatch to 8.1.8.0 and earlier had this right, but it was broken in the split of PGPROC andsinval shared memory arrays.Per report and proposal by Marko Kreen.
1 parentdb20729 commiteeeb782

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

‎src/backend/storage/ipc/procarray.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*
2424
*
2525
* IDENTIFICATION
26-
* $PostgreSQL: pgsql/src/backend/storage/ipc/procarray.c,v 1.47 2009/01/01 17:23:47 momjian Exp $
26+
* $PostgreSQL: pgsql/src/backend/storage/ipc/procarray.c,v 1.48 2009/03/31 05:18:33 heikki Exp $
2727
*
2828
*-------------------------------------------------------------------------
2929
*/
@@ -201,6 +201,7 @@ ProcArrayRemove(PGPROC *proc, TransactionId latestXid)
201201
if (arrayP->procs[index]==proc)
202202
{
203203
arrayP->procs[index]=arrayP->procs[arrayP->numProcs-1];
204+
arrayP->procs[arrayP->numProcs-1]=NULL;/* for debugging */
204205
arrayP->numProcs--;
205206
LWLockRelease(ProcArrayLock);
206207
return;
@@ -1108,6 +1109,20 @@ CountActiveBackends(void)
11081109
{
11091110
volatilePGPROC*proc=arrayP->procs[index];
11101111

1112+
/*
1113+
* Since we're not holding a lock, need to check that the pointer is
1114+
* valid. Someone holding the lock could have incremented numProcs
1115+
* already, but not yet inserted a valid pointer to the array.
1116+
*
1117+
* If someone just decremented numProcs, 'proc' could also point to a
1118+
* PGPROC entry that's no longer in the array. It still points to a
1119+
* PGPROC struct, though, because freed PGPPROC entries just go to
1120+
* the free list and are recycled. Its contents are nonsense in that
1121+
* case, but that's acceptable for this function.
1122+
*/
1123+
if (proc!=NULL)
1124+
continue;
1125+
11111126
if (proc==MyProc)
11121127
continue;/* do not count myself */
11131128
if (proc->pid==0)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp