From 16fc92bf6b95eed0ee7e7097572b4337a27f0573 Mon Sep 17 00:00:00 2001 From: Jason Petersen Date: Mon, 20 Jun 2016 16:14:58 -0600 Subject: [PATCH] Purge connection if re-raising error The only way we re-raise an error is if the raiseError flag is true, so might as well purge connection in that block rather than independently checking errorLevel. --- src/backend/distributed/utils/connection_cache.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/backend/distributed/utils/connection_cache.c b/src/backend/distributed/utils/connection_cache.c index c30b6594a..1998d7760 100644 --- a/src/backend/distributed/utils/connection_cache.c +++ b/src/backend/distributed/utils/connection_cache.c @@ -263,11 +263,6 @@ ReportRemoteError(PGconn *connection, PGresult *result, bool raiseError) sqlStateString[3], sqlStateString[4]); } - if (raiseError) - { - errorLevel = ERROR; - } - /* * If the PGresult did not contain a message, the connection may provide a * suitable top level one. At worst, this is an empty string. @@ -286,6 +281,16 @@ ReportRemoteError(PGconn *connection, PGresult *result, bool raiseError) } } + /* + * If requested, actually raise an error. This necessitates purging the + * connection so it doesn't remain in the hash in an invalid state. + */ + if (raiseError) + { + errorLevel = ERROR; + PurgeConnection(connection); + } + if (sqlState == ERRCODE_CONNECTION_FAILURE) { ereport(errorLevel, (errcode(sqlState),