From ee54c32d2a38da19a045f35294bf9a13e55023eb Mon Sep 17 00:00:00 2001
From: "Stephen R. van den Berg" <srb@cuci.nl>
Date: Thu, 14 May 2020 13:46:00 +0200
Subject: [PATCH] pgsql: Wait till completion on database connection reset.

---
 lib/modules/Sql.pmod/pgsql.pike | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/lib/modules/Sql.pmod/pgsql.pike b/lib/modules/Sql.pmod/pgsql.pike
index 065a91a296..28ded5c82e 100644
--- a/lib/modules/Sql.pmod/pgsql.pike
+++ b/lib/modules/Sql.pmod/pgsql.pike
@@ -501,13 +501,15 @@ protected void destroy() {
   resync();
 }
 
-private void textquery(string q) {
+private .pgsql_util.Result textquery(string q) {
+  .pgsql_util.Result res;
 #if 1
   foreach (q / ";"; ; string sq)
-    big_query(sq);
+    res = big_query(sq);
 #else				// textqueries and portals do not mix well
-  big_query(q, (["_text":1]));
+  res = big_query(q, (["_text":1]));
 #endif
+  return res;
 }
 
 private void resyncdone() {
@@ -518,7 +520,9 @@ private void resyncdone() {
 private void reset_dbsession() {
   proxy.statementsinflight->wait_till_drained();
   error(1);
-  textquery("ROLLBACK;RESET ALL;CLOSE ALL;DISCARD TEMP");
+  .pgsql_util.Result res
+   = textquery("ROLLBACK;RESET ALL;CLOSE ALL;DISCARD TEMP");
+  while (res->fetch_row());
   resyncdone();
 }
 
-- 
GitLab