From 96a477ec896832614334e943080ed199eb29d785 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Thu, 16 May 2019 12:24:04 +0300 Subject: [PATCH] MXS-2490: Send error to client on unknown PS handle If a client requests an unknown binary protocol prepared statement handle, a custom error shows the actual ID used instead of the "empty" ID of 0 that the backend sends. --- .../modules/routing/readwritesplit/rwsplit_route_stmt.cc | 7 ++++++- server/modules/routing/readwritesplit/rwsplitsession.cc | 8 ++++++++ server/modules/routing/readwritesplit/rwsplitsession.hh | 3 +++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc b/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc index 662d91d9c..7cd010668 100644 --- a/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc +++ b/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc @@ -202,7 +202,12 @@ bool RWSplitSession::route_single_stmt(GWBUF* querybuf) SRWBackend target; - if (TARGET_IS_ALL(route_target)) + if (command == MXS_COM_STMT_EXECUTE && stmt_id == 0) + { + // Unknown prepared statement ID + succp = send_unknown_ps_error(extract_binary_ps_id(querybuf)); + } + else if (TARGET_IS_ALL(route_target)) { succp = handle_target_is_all(route_target, querybuf, command, qtype); } diff --git a/server/modules/routing/readwritesplit/rwsplitsession.cc b/server/modules/routing/readwritesplit/rwsplitsession.cc index 676e93937..013bd9489 100644 --- a/server/modules/routing/readwritesplit/rwsplitsession.cc +++ b/server/modules/routing/readwritesplit/rwsplitsession.cc @@ -1221,3 +1221,11 @@ bool RWSplitSession::supports_hint(HINT_TYPE hint_type) const return rv; } + +bool RWSplitSession::send_unknown_ps_error(uint32_t stmt_id) +{ + std::stringstream ss; + ss << "Unknown prepared statement handler (" << stmt_id << ") given to MaxScale"; + GWBUF* err = modutil_create_mysql_err_msg(1, 0, ER_UNKNOWN_STMT_HANDLER, "HY000", ss.str().c_str()); + return m_client->func.write(m_client, err); +} diff --git a/server/modules/routing/readwritesplit/rwsplitsession.hh b/server/modules/routing/readwritesplit/rwsplitsession.hh index 03ffa098a..6860ef0d7 100644 --- a/server/modules/routing/readwritesplit/rwsplitsession.hh +++ b/server/modules/routing/readwritesplit/rwsplitsession.hh @@ -214,6 +214,9 @@ private: mxs::SRWBackend& old_master, mxs::SRWBackend& curr_master); + // Send unknown prepared statement ID error to client + bool send_unknown_ps_error(uint32_t stmt_id); + GWBUF* handle_causal_read_reply(GWBUF* writebuf, mxs::SRWBackend& backend); GWBUF* add_prefix_wait_gtid(SERVER* server, GWBUF* origin); void correct_packet_sequence(GWBUF* buffer);