postgres.git / summary / log / commit / refs
commit b26d76f643277973f90a62f18de30e00edd65378
Author: Nathan Bossart <nathan@postgresql.org>
Date: Wed Nov 12 20:30:11 2025 +0000
First released in: REL_17_STABLE (reverted before release), REL_18_STABLE (reverted before release)
Reverted by: c7e0f263d67f (in 17.8), 8551a289201c (in 18.2), 2dd506b859cf
Teach DSM registry to ERROR if attaching to an uninitialized entry.
If DSM entry initialization fails, backends could try to use an
uninitialized DSM segment, DSA, or dshash table (since the entry is
still added to the registry). To fix, keep track of whether
initialization completed, and ERROR if a backend tries to attach to
an uninitialized entry. We could instead retry initialization as
needed, but that seemed complicated, error prone, and unlikely to
help most cases. Furthermore, such problems probably indicate a
coding error.
Reported-by: Alexander Lakhin <exclusion@gmail.com>
Reviewed-by: Sami Imseih <samimseih@gmail.com>
Discussion: https://postgr.es/m/dd36d384-55df-4fc2-825c-5bc56c950fa9%40gmail.com
Backpatch-through: 17
src/backend/storage/ipc/dsm_registry.c | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/src/backend/storage/ipc/dsm_registry.c b/src/backend/storage/ipc/dsm_registry.c
index 1d4fd31ffed..8511b7afc7b 100644
--- a/src/backend/storage/ipc/dsm_registry.c
+++ b/src/backend/storage/ipc/dsm_registry.c
@@ -45,6 +45,7 @@ typedef struct DSMRegistryEntry
char name[64];
dsm_handle handle;
size_t size;
+ bool initialized;
} DSMRegistryEntry;
static const dshash_parameters dsh_params = {
@@ -158,8 +159,12 @@ GetNamedDSMSegment(const char *name, size_t size,
entry = dshash_find_or_insert(dsm_registry_table, name, found);
if (!(*found))
{
+ dsm_segment *seg;
+
+ entry->initialized = false;
+
/* Initialize the segment. */
- dsm_segment *seg = dsm_create(size, 0);
+ seg = dsm_create(size, 0);
dsm_pin_segment(seg);
dsm_pin_mapping(seg);
@@ -169,13 +174,17 @@ GetNamedDSMSegment(const char *name, size_t size,
if (init_callback)
(*init_callback) (ret);
+
+ entry->initialized = true;
}
+ else if (!entry->initialized)
+ ereport(ERROR,
+ (errmsg("requested DSM segment \"%s\" failed initialization",
+ name)));
else if (entry->size != size)
- {
ereport(ERROR,
- (errmsg("requested DSM segment size does not match size of "
- "existing segment")));
- }
+ (errmsg("requested DSM segment \"%s\" does not match size of existing entry",
+ name)));
else
{
dsm_segment *seg = dsm_find_mapping(entry->handle);
[parent: 82fa6b78dba1]