From 8551f77ab4a7b8e08ca9319a53752b445b7d59d6 Mon Sep 17 00:00:00 2001 From: "Stephen R. van den Berg" <srb@cuci.nl> Date: Wed, 12 Oct 2016 18:27:00 +0200 Subject: [PATCH] pgsql: Drop termination lock even on exceptions. Prevent cancelquery() from starting the statemachine. This was responsible for the majority of the exceptions. --- lib/modules/Sql.pmod/pgsql.h | 2 +- lib/modules/Sql.pmod/pgsql.pike | 18 ++++++++++++++---- lib/modules/Sql.pmod/pgsql_util.pmod | 12 +++++++++--- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/lib/modules/Sql.pmod/pgsql.h b/lib/modules/Sql.pmod/pgsql.h index d0b31cbf28..b8056f277e 100644 --- a/lib/modules/Sql.pmod/pgsql.h +++ b/lib/modules/Sql.pmod/pgsql.h @@ -72,7 +72,7 @@ #ifdef PG_DEBUG #define PD(X ...) werror(X) // PT() puts this in the backtrace -#define PT(X ...) (lambda(object _this){return (X);}(this)) +#define PT(X ...) (lambda(object _this){(X);}(this)) #else #undef PG_DEBUGMORE #define PD(X ...) 0 diff --git a/lib/modules/Sql.pmod/pgsql.pike b/lib/modules/Sql.pmod/pgsql.pike index 3661637f89..30c93353f0 100644 --- a/lib/modules/Sql.pmod/pgsql.pike +++ b/lib/modules/Sql.pmod/pgsql.pike @@ -313,7 +313,7 @@ private .pgsql_util.conxion getsocket(void|int nossl) { //! through the generic SQL-interface. /*semi*/final void cancelquery() { PD("CancelRequest\n"); - .pgsql_util.conxion lcon=getsocket(1); + .pgsql_util.conxion lcon=getsocket(2); lcon->add_int32(16)->add_int32(PG_PROTOCOL(1234,5678)) ->add_int32(backendpid)->add(cancelsecret)->sendcmd(FLUSHSEND); lcon=0; @@ -617,6 +617,7 @@ final void _processloop(.pgsql_util.conxion ci) { _connectfail(); else destruct(waitforauthready); + unnamedstatement=0; termlock=0; return; } @@ -625,10 +626,11 @@ final void _processloop(.pgsql_util.conxion ci) { } private void procmessage() { + mixed err; int terminating=0; + err = catch { .pgsql_util.conxion ci=c; // cache value FIXME sensible? .pgsql_util.conxiin cr=ci->i; // cache value FIXME sensible? - mixed err; #ifdef PG_DEBUG PD("Processloop\n"); @@ -1190,6 +1192,12 @@ private void procmessage() { termlock=0; if(err && !stringp(err)) throw(err); + }; + if (err) { + unnamedstatement=0; + termlock = 0; + throw(err); + } } //! Closes the connection to the database, any running queries are @@ -1201,9 +1209,11 @@ private void procmessage() { /*semi*/final void close() { if(qportals && qportals->size()) catch(cancelquery()); - termlock=unnamedstatement->lock(1); + if (unnamedstatement) + termlock=unnamedstatement->lock(1); c->close(); - unnamedstatement->lock(1); + if (unnamedstatement) + unnamedstatement->lock(1); destruct(c);destruct(waitforauthready); } diff --git a/lib/modules/Sql.pmod/pgsql_util.pmod b/lib/modules/Sql.pmod/pgsql_util.pmod index f30e388b99..2eaec13420 100644 --- a/lib/modules/Sql.pmod/pgsql_util.pmod +++ b/lib/modules/Sql.pmod/pgsql_util.pmod @@ -208,7 +208,11 @@ class conxiin { } final int read_cb(mixed id,mixed b) { - PD("Read callback %O\n",(string)b); + PD("Read callback %O\n",((string)b) +#ifndef PG_DEBUGMORE + [..255] +#endif + ); Thread.MutexKey lock=fillreadmux->lock(); if(procmsg&&id) procmsg=0,lock=0,Thread.Thread(id); @@ -411,8 +415,10 @@ outer: socket->set_backend(local_backend); socket->set_buffer_mode(i,0); socket->set_nonblocking(i->read_cb,write_cb,close); - connectfail=pgsqlsess->_connectfail; - Thread.Thread(pgsqlsess->_processloop,this); + if (nossl != 2) { + connectfail=pgsqlsess->_connectfail; + Thread.Thread(pgsqlsess->_processloop,this); + } return; }; catch(connectfail(err)); -- GitLab