aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Munro <tmunro@postgresql.org>2019-02-18 09:53:26 +1300
committerThomas Munro <tmunro@postgresql.org>2019-02-18 09:59:27 +1300
commit1d93d180454f9da74677dd0498f5408efe6b603d (patch)
tree291787be2f32fb4e947db144e7b00fa881dff51a
parent7f39f0344129706979174ba530f8cc21b7d9f4a3 (diff)
downloadpostgresql-1d93d180454f9da74677dd0498f5408efe6b603d.tar.gz
postgresql-1d93d180454f9da74677dd0498f5408efe6b603d.zip
Fix race in dsm_unpin_segment() when handles are reused.
Teach dsm_unpin_segment() to skip segments that are in the process of being destroyed by another backend, when searching for a handle. Such a segment cannot possibly be the one we are looking for, even if its handle matches. Another slot might hold a recently created segment that has the same handle value by coincidence, and we need to keep searching for that one. The bug caused rare "cannot unpin a segment that is not pinned" errors on 10 and 11. Similar to commit 6c0fb941 for dsm_attach(). Back-patch to 10, where dsm_unpin_segment() landed. Author: Thomas Munro Reported-by: Justin Pryzby Tested-by: Justin Pryzby (along with other recent DSA/DSM fixes) Discussion: https://postgr.es/m/20190216023854.GF30291@telsasoft.com
-rw-r--r--src/backend/storage/ipc/dsm.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/backend/storage/ipc/dsm.c b/src/backend/storage/ipc/dsm.c
index fde420d6edb..ef509d99b5d 100644
--- a/src/backend/storage/ipc/dsm.c
+++ b/src/backend/storage/ipc/dsm.c
@@ -891,8 +891,8 @@ dsm_unpin_segment(dsm_handle handle)
LWLockAcquire(DynamicSharedMemoryControlLock, LW_EXCLUSIVE);
for (i = 0; i < dsm_control->nitems; ++i)
{
- /* Skip unused slots. */
- if (dsm_control->item[i].refcnt == 0)
+ /* Skip unused slots and segments that are concurrently going away. */
+ if (dsm_control->item[i].refcnt <= 1)
continue;
/* If we've found our handle, we can stop searching. */