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

Commit2034519

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 parent3967737 commit2034519

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
@@ -361,10 +361,18 @@ SyncRepCancelWait(void)
361361
void
362362
SyncRepCleanupAtProcExit(void)
363363
{
364+
/*
365+
* First check if we are removed from the queue without the lock to not
366+
* slow down backend exit.
367+
*/
364368
if (!SHMQueueIsDetached(&(MyProc->syncRepLinks)))
365369
{
366370
LWLockAcquire(SyncRepLock,LW_EXCLUSIVE);
367-
SHMQueueDelete(&(MyProc->syncRepLinks));
371+
372+
/* maybe we have just been removed, so recheck */
373+
if (!SHMQueueIsDetached(&(MyProc->syncRepLinks)))
374+
SHMQueueDelete(&(MyProc->syncRepLinks));
375+
368376
LWLockRelease(SyncRepLock);
369377
}
370378
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp