Skip to content

Commit b709662

Browse files
committed
Hold required lock when initializing shmem
According to the documentation, each backend is supposed to hold AddinShmemInitLock when calling ShmemInitStruct. We only did that for half of our calls before this patch.
1 parent ff8a389 commit b709662

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

contrib/pg_tde/src/access/pg_tde_xlog_smgr.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ TDEXLogShmemInit(void)
158158
{
159159
bool foundBuf;
160160

161+
Assert(LWLockHeldByMeInMode(AddinShmemInitLock, LW_EXCLUSIVE));
162+
161163
EncryptionState = (EncryptionStateData *)
162164
ShmemInitStruct("TDE XLog Encryption State",
163165
TDEXLogEncryptStateSize(),

contrib/pg_tde/src/catalog/tde_principal_key.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ PrincipalKeyShmemInit(void)
127127
char *free_start;
128128
Size required_shmem_size = PrincipalKeyShmemSize();
129129

130-
LWLockAcquire(AddinShmemInitLock, LW_EXCLUSIVE);
130+
Assert(LWLockHeldByMeInMode(AddinShmemInitLock, LW_EXCLUSIVE));
131131

132132
/* Create or attach to the shared memory state */
133133
ereport(NOTICE, errmsg("PrincipalKeyShmemInit: requested %ld bytes", required_shmem_size));
@@ -175,8 +175,6 @@ PrincipalKeyShmemInit(void)
175175

176176
dshash_detach(dsh);
177177
}
178-
179-
LWLockRelease(AddinShmemInitLock);
180178
}
181179

182180
/*

contrib/pg_tde/src/pg_tde.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,15 @@ tde_shmem_startup(void)
6464
if (prev_shmem_startup_hook)
6565
prev_shmem_startup_hook();
6666

67+
LWLockAcquire(AddinShmemInitLock, LW_EXCLUSIVE);
68+
6769
KeyProviderShmemInit();
6870
PrincipalKeyShmemInit();
6971
TDEXLogShmemInit();
7072
TDEXLogSmgrInit();
7173
TDEXLogSmgrInitWrite(EncryptXLog);
74+
75+
LWLockRelease(AddinShmemInitLock);
7276
}
7377

7478
void

0 commit comments

Comments
 (0)