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

Commitebe3344

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 parent62acbda commitebe3344

File tree

2 files changed

+30
-15
lines changed

2 files changed

+30
-15
lines changed

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

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

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

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

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,7 @@ ProcKill(int code, Datum arg)
760760
{
761761
/* use volatile pointer to prevent code rearrangement */
762762
volatilePROC_HDR*procglobal=ProcGlobal;
763+
PGPROC*proc;
763764

764765
Assert(MyProc!=NULL);
765766

@@ -784,26 +785,29 @@ ProcKill(int code, Datum arg)
784785
*/
785786
LWLockReleaseAll();
786787

787-
/* Release ownership of the process's latch, too */
788-
DisownLatch(&MyProc->procLatch);
788+
/*
789+
* Clear MyProc first; then disown the process latch. This is so that
790+
* signal handlers won't try to clear the process latch after it's no
791+
* longer ours.
792+
*/
793+
proc=MyProc;
794+
MyProc=NULL;
795+
DisownLatch(&proc->procLatch);
789796

790797
SpinLockAcquire(ProcStructLock);
791798

792799
/* Return PGPROC structure (and semaphore) to appropriate freelist */
793800
if (IsAnyAutoVacuumProcess())
794801
{
795-
MyProc->links.next= (SHM_QUEUE*)procglobal->autovacFreeProcs;
796-
procglobal->autovacFreeProcs=MyProc;
802+
proc->links.next= (SHM_QUEUE*)procglobal->autovacFreeProcs;
803+
procglobal->autovacFreeProcs=proc;
797804
}
798805
else
799806
{
800-
MyProc->links.next= (SHM_QUEUE*)procglobal->freeProcs;
801-
procglobal->freeProcs=MyProc;
807+
proc->links.next= (SHM_QUEUE*)procglobal->freeProcs;
808+
procglobal->freeProcs=proc;
802809
}
803810

804-
/* PGPROC struct isn't mine anymore */
805-
MyProc=NULL;
806-
807811
/* Update shared estimate of spins_per_delay */
808812
procglobal->spins_per_delay=update_spins_per_delay(procglobal->spins_per_delay);
809813

@@ -832,6 +836,7 @@ AuxiliaryProcKill(int code, Datum arg)
832836
{
833837
intproctype=DatumGetInt32(arg);
834838
PGPROC*auxprocPG_USED_FOR_ASSERTS_ONLY;
839+
PGPROC*proc;
835840

836841
Assert(proctype >=0&&proctype<NUM_AUXILIARY_PROCS);
837842

@@ -842,16 +847,19 @@ AuxiliaryProcKill(int code, Datum arg)
842847
/* Release any LW locks I am holding (see notes above) */
843848
LWLockReleaseAll();
844849

845-
/* Release ownership of the process's latch, too */
846-
DisownLatch(&MyProc->procLatch);
850+
/*
851+
* Clear MyProc first; then disown the process latch. This is so that
852+
* signal handlers won't try to clear the process latch after it's no
853+
* longer ours.
854+
*/
855+
proc=MyProc;
856+
MyProc=NULL;
857+
DisownLatch(&proc->procLatch);
847858

848859
SpinLockAcquire(ProcStructLock);
849860

850861
/* Mark auxiliary proc no longer in use */
851-
MyProc->pid=0;
852-
853-
/* PGPROC struct isn't mine anymore */
854-
MyProc=NULL;
862+
proc->pid=0;
855863

856864
/* Update shared estimate of spins_per_delay */
857865
ProcGlobal->spins_per_delay=update_spins_per_delay(ProcGlobal->spins_per_delay);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp