From f7cb83fd7f5c9a61f9de730b0102db7427a643a0 Mon Sep 17 00:00:00 2001 From: Pavan Deolasee Date: Wed, 19 Aug 2015 08:43:23 +0530 Subject: [PATCH] Use ErrorContext to save error messages in ResponseCombiner. This should avoid any references to memory which gets otherwise freed during error handling. Also make sure that remote transactions are properly aborted upon failure to send commands --- src/backend/pgxc/pool/execRemote.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/backend/pgxc/pool/execRemote.c b/src/backend/pgxc/pool/execRemote.c index cf5391df49..8d7d4da593 100644 --- a/src/backend/pgxc/pool/execRemote.c +++ b/src/backend/pgxc/pool/execRemote.c @@ -596,8 +596,10 @@ HandleCommandComplete(RemoteQueryState *combiner, char *msg_body, size_t len, PG */ if (combiner->errorMessage == NULL) { + MemoryContext oldcontext = MemoryContextSwitchTo(ErrorContext); combiner->errorMessage = pstrdup("unexpected ROLLBACK from remote node"); + MemoryContextSwitchTo(oldcontext); /* * ERRMSG_PRODUCER_ERROR * Messages with this code are replaced by others, if they are @@ -1049,6 +1051,7 @@ HandleError(RemoteQueryState *combiner, char *msg_body, size_t len) combiner->errorCode[2], combiner->errorCode[3], combiner->errorCode[4]) == ERRCODE_PRODUCER_ERROR) { + MemoryContext oldcontext = MemoryContextSwitchTo(ErrorContext); combiner->errorMessage = pstrdup(message); /* Error Code is exactly 5 significant bytes */ if (code) @@ -1057,6 +1060,7 @@ HandleError(RemoteQueryState *combiner, char *msg_body, size_t len) combiner->errorDetail = pstrdup(detail); if (hint) combiner->errorHint = pstrdup(hint); + MemoryContextSwitchTo(oldcontext); } /* @@ -5241,6 +5245,7 @@ do_query(RemoteQueryState *node) if (!pgxc_start_command_on_connection(primaryconnection, node, snapshot)) { + pgxc_node_remote_abort(); pfree(connections); pfree(primaryconnection); ereport(ERROR, @@ -5280,6 +5285,7 @@ do_query(RemoteQueryState *node) if (!pgxc_start_command_on_connection(connections[i], node, snapshot)) { + pgxc_node_remote_abort(); pfree(connections); if (primaryconnection) pfree(primaryconnection); @@ -7583,6 +7589,7 @@ ExecRemoteQuery(RemoteQueryState *node) /* If explicit transaction is needed gxid is already sent */ if (!pgxc_start_command_on_connection(primaryconnection, node, snapshot)) { + pgxc_node_remote_abort(); pfree_pgxc_all_handles(pgxc_connections); ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), @@ -7622,6 +7629,7 @@ ExecRemoteQuery(RemoteQueryState *node) /* If explicit transaction is needed gxid is already sent */ if (!pgxc_start_command_on_connection(connections[i], node, snapshot)) { + pgxc_node_remote_abort(); pfree_pgxc_all_handles(pgxc_connections); ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), -- 2.39.5