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

Commit61f2383

Browse files
committed
Fix race condition at backend exit when deleting element in syncrep queue
When a backend exits, it gets deleted from the syncrep queue if present.The queue was checked without SyncRepLock taken in exclusive mode, so itwould have been possible for a backend to remove itself after a WALsender already did the job. Fix this issue based on a suggestion fromFujii Masao, by first checking the queue without the lock. Then, if thebackend is present in the queue, take the lock and perform an additionallookup check before doing the element deletion.Author: Dongming LiuReviewed-by: Kyotaro Horiguchi, Fujii Masao, Michael PaquierDiscussion:https://postgr.es/m/a0806273-8bbb-43b3-bbe1-c45a58f6ae21.lingce.ldm@alibaba-inc.comBackpatch-through: 9.4
1 parent3b24cf7 commit61f2383

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

‎src/backend/replication/syncrep.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,10 +360,18 @@ SyncRepCancelWait(void)
360360
void
361361
SyncRepCleanupAtProcExit(void)
362362
{
363+
/*
364+
* First check if we are removed from the queue without the lock to not
365+
* slow down backend exit.
366+
*/
363367
if (!SHMQueueIsDetached(&(MyProc->syncRepLinks)))
364368
{
365369
LWLockAcquire(SyncRepLock,LW_EXCLUSIVE);
366-
SHMQueueDelete(&(MyProc->syncRepLinks));
370+
371+
/* maybe we have just been removed, so recheck */
372+
if (!SHMQueueIsDetached(&(MyProc->syncRepLinks)))
373+
SHMQueueDelete(&(MyProc->syncRepLinks));
374+
367375
LWLockRelease(SyncRepLock);
368376
}
369377
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp