From 17619ae8912cdd7d4dff6d7edc22e61c4e28a558 Mon Sep 17 00:00:00 2001
From: "Stephen R. van den Berg" <srb@cuci.nl>
Date: Tue, 6 Apr 2021 06:35:07 +0200
Subject: [PATCH] pgsql: Avoid recursive errors in case of async destruct.

---
 lib/modules/Sql.pmod/pgsql_util.pmod | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lib/modules/Sql.pmod/pgsql_util.pmod b/lib/modules/Sql.pmod/pgsql_util.pmod
index 8ae289da7b..425724c60c 100644
--- a/lib/modules/Sql.pmod/pgsql_util.pmod
+++ b/lib/modules/Sql.pmod/pgsql_util.pmod
@@ -481,8 +481,9 @@ class conxion {
       PD("Nostash locked by %s\n",
        describe_backtrace(nostash->current_locking_thread()->backtrace()));
 #endif
-    while (lock = (intp(waitforreal) && waitforreal > 0
-                   ? nostash->lock : nostash->trylock)(1)) {
+    while (lock = nostash
+               && ((intp(waitforreal) && waitforreal > 0
+                   ? nostash->lock : nostash->trylock)(1))) {
       int mode;
       if (sizeof(stash) && (mode = getstash(KEEP)) > KEEP)
         sendcmd(mode);		// Force out stash to the server
-- 
GitLab