diff --git a/src/protocol/pool_proto_modules.c b/src/protocol/pool_proto_modules.c index 11befe979..e030e7b6d 100644 --- a/src/protocol/pool_proto_modules.c +++ b/src/protocol/pool_proto_modules.c @@ -222,20 +222,39 @@ SimpleQuery(POOL_CONNECTION *frontend, strlcpy(query_string_buffer, contents, sizeof(query_string_buffer)); /* - * Check if extended query protocol message ended. If not, reject the - * query and raise an error to terminate the session to avoid hanging up. - * However if we are processing a reset query (frontend == NULL), we skip - * the check as we don't want to raise a error. + * Check if extended query protocol message ended. If not, process any + * pending response from backend using ProcessBackendResponse(). However + * if we are processing a reset query (frontend == NULL), we skip the + * check as we don't need to care about any pending response from backend. */ if (SL_MODE) { + int state; + short num_fields; + if (frontend != NULL && (pool_is_doing_extended_query_message() || - pool_pending_message_head_message())) - - ereport(FATAL, + pool_pending_message_exists())) + { + ereport(DEBUG1, (errmsg("simple query \"%s\" arrived before ending an extended query message", query_string_buffer))); + + /* if pending message exists, process it */ + while (pool_pending_message_exists()) + { + /* + * read_kind_from_backend requires that query is inprogress + * and doing extended query state because it needs to refer to + * proper query context in session context. + */ + pool_set_query_in_progress(); + pool_set_doing_extended_query_message(); + /* process pending responses from backend */ + ProcessBackendResponse(frontend, backend, &state, &num_fields); + } + } + pool_unset_doing_extended_query_message(); } /* show ps status */ @@ -3080,6 +3099,12 @@ ProcessFrontendResponse(POOL_CONNECTION *frontend, return status; } +/* + * Read one backend response and process it. + * + * state: used for processing reset query + * num_fields: used in V2 protocol + */ POOL_STATUS ProcessBackendResponse(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend,