From 24f6d4bbe7f0cdb0c828f055e7f9d63aa1e3f7c7 Mon Sep 17 00:00:00 2001 From: "Stephen R. van den Berg" <srb@cuci.nl> Date: Wed, 21 Jun 2017 11:57:06 +0200 Subject: [PATCH] pgsql: Flush out unseen error/warning messages upon connection close. --- lib/modules/Sql.pmod/pgsql.pike | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/modules/Sql.pmod/pgsql.pike b/lib/modules/Sql.pmod/pgsql.pike index 76a90a2b99..b92979a36b 100644 --- a/lib/modules/Sql.pmod/pgsql.pike +++ b/lib/modules/Sql.pmod/pgsql.pike @@ -1218,6 +1218,7 @@ private void procmessage() { //! This function is PostgreSQL-specific, and thus it is not available //! through the generic SQL-interface. /*semi*/final void close() { + throwdelayederror(this); Thread.MutexKey lock; if (qportals && qportals->size()) catch(cancelquery()); @@ -1232,8 +1233,17 @@ private void procmessage() { } protected void destroy() { - catch(close()); + string errstring; + mixed err = catch(close()); .pgsql_util.unregister_backend(); + /* + * Flush out any asynchronously reported errors to stderr; because we are + * inside a destructor, throwing an error will not work anymore. + */ + if (err || (err = catch(errstring = error(1)))) + werror(describe_backtrace(err)); + else if (sizeof(errstring)) + werror(errstring); } final void _connectfail(void|mixed err) { -- GitLab