0001-Detach-from-DSM-segments-last-in-resowner.c.patch
application/octet-stream
Filename: 0001-Detach-from-DSM-segments-last-in-resowner.c.patch
Type: application/octet-stream
Part: 0
Patch
Format: format-patch
Series: patch 0001
Subject: Detach from DSM segments last in resowner.c.
| File | + | − |
|---|---|---|
| src/backend/utils/resowner/resowner.c | 10 | 10 |
From 92f678b6cef5a6b5a8fbd7d05b201987d52a8060 Mon Sep 17 00:00:00 2001
From: Thomas Munro <thomas.munro@enterprisedb.com>
Date: Thu, 29 Nov 2018 12:24:07 +1300
Subject: [PATCH] Detach from DSM segments last in resowner.c.
It turns out that Windows' FILE_SHARE_DELETE mode doesn't quite give
POSIX semantics for unlink(). While it lets you unlink a file or
a directory that has an open handle, it doesn't let you unlink a
directory that previously contained a file that has an open handle.
This has the consequence that an error raised while a SharedFileSet
exists can cause us to fail to unlink a temporary directory, even
though all the files within it have been unlinked. We log a WARNING
and leak the empty directory until the next restart eventually cleans
it up.
Fix, by detaching from DSM segments only after we have closed all
file handles. Since SharedFileSet uses a DSM detach hook to unlink
files only when the last backend detaches, it's only our own file
handles that we have to worry about.
This was a secondary issue discovered while investigating bug #15460.
Author: Thomas Munro
Discussion: https://postgr.es/m/15460-b6db80de822fa0ad@postgresql.org
Discussion: https://postgr.es/m/CAEepm=1Ugp7mNFX-YpSfWr0F_6QA4jzjtavauBcoAAZGd7_tPA@mail.gmail.com
---
src/backend/utils/resowner/resowner.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/resowner/resowner.c b/src/backend/utils/resowner/resowner.c
index 211833da02c..004693234ea 100644
--- a/src/backend/utils/resowner/resowner.c
+++ b/src/backend/utils/resowner/resowner.c
@@ -535,16 +535,6 @@ ResourceOwnerReleaseInternal(ResourceOwner owner,
RelationClose(res);
}
- /* Ditto for dynamic shared memory segments */
- while (ResourceArrayGetAny(&(owner->dsmarr), &foundres))
- {
- dsm_segment *res = (dsm_segment *) DatumGetPointer(foundres);
-
- if (isCommit)
- PrintDSMLeakWarning(res);
- dsm_detach(res);
- }
-
/* Ditto for JIT contexts */
while (ResourceArrayGetAny(&(owner->jitarr), &foundres))
{
@@ -668,6 +658,16 @@ ResourceOwnerReleaseInternal(ResourceOwner owner,
PrintFileLeakWarning(res);
FileClose(res);
}
+
+ /* Ditto for dynamic shared memory segments */
+ while (ResourceArrayGetAny(&(owner->dsmarr), &foundres))
+ {
+ dsm_segment *res = (dsm_segment *) DatumGetPointer(foundres);
+
+ if (isCommit)
+ PrintDSMLeakWarning(res);
+ dsm_detach(res);
+ }
}
/* Let add-on modules get a chance too */
--
2.19.1