diff options
author | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2023-11-23 13:31:36 +0200 |
---|---|---|
committer | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2023-11-23 13:31:36 +0200 |
commit | 50c67c2019ab9ade8aa8768bfe604cd802fe8591 (patch) | |
tree | 9dcc8f840dea2de613efaa2bddb1206e8bb1d33c /src/include | |
parent | 414e75540f058b23377219586abb3008507f7099 (diff) |
Use ResourceOwner to track WaitEventSets.
A WaitEventSet holds file descriptors or event handles (on Windows).
If FreeWaitEventSet is not called, those fds or handles are leaked.
Use ResourceOwners to track WaitEventSets, to clean those up
automatically on error.
This was a live bug in async Append nodes, if a FDW's
ForeignAsyncRequest function failed. (In back branches, I will apply a
more localized fix for that based on PG_TRY-PG_FINALLY.)
The added test doesn't check for leaking resources, so it passed even
before this commit. But at least it covers the code path.
In the passing, fix misleading comment on what the 'nevents' argument
to WaitEventSetWait means.
Report by Alexander Lakhin, analysis and suggestion for the fix by
Tom Lane. Fixes bug #17828.
Reviewed-by: Alexander Lakhin, Thomas Munro
Discussion: https://www.postgresql.org/message-id/472235.1678387869@sss.pgh.pa.us
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/storage/latch.h | 4 | ||||
-rw-r--r-- | src/include/utils/resowner.h | 1 |
2 files changed, 4 insertions, 1 deletions
diff --git a/src/include/storage/latch.h b/src/include/storage/latch.h index 99cc47874ac..9efc33add8f 100644 --- a/src/include/storage/latch.h +++ b/src/include/storage/latch.h @@ -102,6 +102,8 @@ #include <signal.h> +#include "utils/resowner.h" + /* * Latch structure should be treated as opaque and only accessed through * the public functions. It is defined here to allow embedding Latches as @@ -173,7 +175,7 @@ extern void SetLatch(Latch *latch); extern void ResetLatch(Latch *latch); extern void ShutdownLatchSupport(void); -extern WaitEventSet *CreateWaitEventSet(MemoryContext context, int nevents); +extern WaitEventSet *CreateWaitEventSet(ResourceOwner resowner, int nevents); extern void FreeWaitEventSet(WaitEventSet *set); extern void FreeWaitEventSetAfterFork(WaitEventSet *set); extern int AddWaitEventToSet(WaitEventSet *set, uint32 events, pgsocket fd, diff --git a/src/include/utils/resowner.h b/src/include/utils/resowner.h index 0735480214e..ddbf19d8da0 100644 --- a/src/include/utils/resowner.h +++ b/src/include/utils/resowner.h @@ -74,6 +74,7 @@ typedef uint32 ResourceReleasePriority; #define RELEASE_PRIO_TUPDESC_REFS 400 #define RELEASE_PRIO_SNAPSHOT_REFS 500 #define RELEASE_PRIO_FILES 600 +#define RELEASE_PRIO_WAITEVENTSETS 700 /* 0 is considered invalid */ #define RELEASE_PRIO_FIRST 1 |