From 57c609ef4a17a3dd2ca4f689ee8f7d81854dafb4 Mon Sep 17 00:00:00 2001 From: Artem Gavrilov Date: Fri, 14 Feb 2025 19:21:48 +0200 Subject: [PATCH] PG-1349 Fix deadlock --- pg_stat_monitor.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pg_stat_monitor.c b/pg_stat_monitor.c index 310ea8c..f205bf4 100644 --- a/pg_stat_monitor.c +++ b/pg_stat_monitor.c @@ -1968,6 +1968,9 @@ pgsm_store(pgsmEntry *entry) * we need to create the entry. */ LWLockAcquire(pgsm->lock, LW_SHARED); + + PG_TRY(); + { shared_hash_entry = (pgsmEntry *) pgsm_hash_find(get_pgsmHash(), &entry->key, &found); if (!shared_hash_entry) @@ -2008,8 +2011,6 @@ pgsm_store(pgsmEntry *entry) } PG_CATCH(); { - LWLockRelease(pgsm->lock); - if (DsaPointerIsValid(dsa_query_pointer)) dsa_free(query_dsa_area, dsa_query_pointer); PG_RE_THROW(); @@ -2082,6 +2083,15 @@ pgsm_store(pgsmEntry *entry) PGSM_STORE); memset(&entry->counters, 0, sizeof(entry->counters)); + + } + PG_CATCH(); + { + HOLD_INTERRUPTS(); + LWLockRelease(pgsm->lock); + PG_RE_THROW(); + } + PG_END_TRY(); LWLockRelease(pgsm->lock); }