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

Commit5d807a7

Browse files
committed
Clear MyProc and MyProcSignalState before they become invalid.
Evidence from buildfarm member crake suggests that the new test_shm_mqmodule is routinely crashing the server due to the arrival of a SIGUSR1after the shared memory segment has been unmapped. Although processesusing the new dynamic background worker facilities are more likely toreceive a SIGUSR1 around this time, the problem is also possible on olderbranches, so I'm back-patching the parts of this change that apply toolder branches as far as they apply.It's already generally the case that code checks whether these pointersare NULL before deferencing them, so the important thing is mostly tomake sure that they do get set to NULL before they become invalid. Butin master, there's one case in procsignal_sigusr1_handler that lacks aNULL guard, so add that.Patch by me; review by Tom Lane.
1 parent5dc6cab commit5d807a7

File tree

2 files changed

+32
-17
lines changed

2 files changed

+32
-17
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,13 @@ CleanupProcSignalState(int status, Datum arg)
140140
slot=&ProcSignalSlots[pss_idx-1];
141141
Assert(slot==MyProcSignalSlot);
142142

143+
/*
144+
* Clear MyProcSignalSlot, so that a SIGUSR1 received after this point
145+
* won't try to access it after it's no longer ours (and perhaps even
146+
* after we've unmapped the shared memory segment).
147+
*/
148+
MyProcSignalSlot=NULL;
149+
143150
/* sanity check */
144151
if (slot->pss_pid!=MyProcPid)
145152
{

‎src/backend/storage/lmgr/proc.c

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,7 @@ ProcKill(int code, Datum arg)
774774
{
775775
/* use volatile pointer to prevent code rearrangement */
776776
volatilePROC_HDR*procglobal=ProcGlobal;
777+
PGPROC*proc;
777778

778779
Assert(MyProc!=NULL);
779780

@@ -798,31 +799,34 @@ ProcKill(int code, Datum arg)
798799
*/
799800
LWLockReleaseAll();
800801

801-
/* Release ownership of the process's latch, too */
802-
DisownLatch(&MyProc->procLatch);
802+
/*
803+
* Clear MyProc first; then disown the process latch. This is so that
804+
* signal handlers won't try to clear the process latch after it's no
805+
* longer ours.
806+
*/
807+
proc=MyProc;
808+
MyProc=NULL;
809+
DisownLatch(&proc->procLatch);
803810

804811
SpinLockAcquire(ProcStructLock);
805812

806813
/* Return PGPROC structure (and semaphore) to appropriate freelist */
807814
if (IsAnyAutoVacuumProcess())
808815
{
809-
MyProc->links.next= (SHM_QUEUE*)procglobal->autovacFreeProcs;
810-
procglobal->autovacFreeProcs=MyProc;
816+
proc->links.next= (SHM_QUEUE*)procglobal->autovacFreeProcs;
817+
procglobal->autovacFreeProcs=proc;
811818
}
812819
elseif (IsBackgroundWorker)
813820
{
814-
MyProc->links.next= (SHM_QUEUE*)procglobal->bgworkerFreeProcs;
815-
procglobal->bgworkerFreeProcs=MyProc;
821+
proc->links.next= (SHM_QUEUE*)procglobal->bgworkerFreeProcs;
822+
procglobal->bgworkerFreeProcs=proc;
816823
}
817824
else
818825
{
819-
MyProc->links.next= (SHM_QUEUE*)procglobal->freeProcs;
820-
procglobal->freeProcs=MyProc;
826+
proc->links.next= (SHM_QUEUE*)procglobal->freeProcs;
827+
procglobal->freeProcs=proc;
821828
}
822829

823-
/* PGPROC struct isn't mine anymore */
824-
MyProc=NULL;
825-
826830
/* Update shared estimate of spins_per_delay */
827831
procglobal->spins_per_delay=update_spins_per_delay(procglobal->spins_per_delay);
828832

@@ -851,6 +855,7 @@ AuxiliaryProcKill(int code, Datum arg)
851855
{
852856
intproctype=DatumGetInt32(arg);
853857
PGPROC*auxprocPG_USED_FOR_ASSERTS_ONLY;
858+
PGPROC*proc;
854859

855860
Assert(proctype >=0&&proctype<NUM_AUXILIARY_PROCS);
856861

@@ -861,16 +866,19 @@ AuxiliaryProcKill(int code, Datum arg)
861866
/* Release any LW locks I am holding (see notes above) */
862867
LWLockReleaseAll();
863868

864-
/* Release ownership of the process's latch, too */
865-
DisownLatch(&MyProc->procLatch);
869+
/*
870+
* Clear MyProc first; then disown the process latch. This is so that
871+
* signal handlers won't try to clear the process latch after it's no
872+
* longer ours.
873+
*/
874+
proc=MyProc;
875+
MyProc=NULL;
876+
DisownLatch(&proc->procLatch);
866877

867878
SpinLockAcquire(ProcStructLock);
868879

869880
/* Mark auxiliary proc no longer in use */
870-
MyProc->pid=0;
871-
872-
/* PGPROC struct isn't mine anymore */
873-
MyProc=NULL;
881+
proc->pid=0;
874882

875883
/* Update shared estimate of spins_per_delay */
876884
ProcGlobal->spins_per_delay=update_spins_per_delay(ProcGlobal->spins_per_delay);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp