Improve handleError error messages

The hangup and error handlers now have unique messages. Although the
behavior in the handlers is practically the same in both cases, the cause
of the error is not the same.

If a socket error is present, it is added to the error message. If an
error is present, it should clearly show the reason why the TCP socket was
closed.

The is_fake_event boolean helps distinguish fake events from real
ones. This makes figuring out the real source of hangup events easier.
This commit is contained in:
Markus Mäkelä
2019-12-12 21:12:11 +02:00
parent 44664132bc
commit e057c751cd
3 changed files with 30 additions and 4 deletions

View File

@ -25,6 +25,8 @@
#include <maxscale/server.hh>
#include <maxscale/utils.h>
#include <sstream>
/*
* MySQL Protocol module for handling the protocol between the gateway
* and the backend MySQL database.
@ -585,6 +587,23 @@ static int gw_read_backend_event(DCB* dcb)
return rc;
}
static std::string get_detailed_error(DCB* dcb)
{
std::ostringstream ss;
if (int err = gw_getsockerrno(dcb->fd))
{
ss << " (" << err << ", " << mxs_strerror(err) << ")";
}
else if (dcb->is_fake_event)
{
// Fake events should not have TCP socket errors
ss << " (Generated event)";
}
return ss.str();
}
static void do_handle_error(DCB* dcb, mxs_error_action_t action, const char* errmsg)
{
bool succp = true;
@ -592,7 +611,7 @@ static void do_handle_error(DCB* dcb, mxs_error_action_t action, const char* err
if (!dcb->dcb_errhandle_called)
{
GWBUF* errbuf = mysql_create_custom_error(1, 0, errmsg);
GWBUF* errbuf = mysql_create_custom_error(1, 0, (errmsg + get_detailed_error(dcb)).c_str());
MXS_ROUTER_SESSION* rsession = static_cast<MXS_ROUTER_SESSION*>(session->router_session);
MXS_ROUTER_OBJECT* router = session->service->router;
MXS_ROUTER* router_instance = session->service->router_instance;
@ -1340,7 +1359,7 @@ static int gw_error_backend_event(DCB* dcb)
}
else
{
do_handle_error(dcb, ERRACT_NEW_CONNECTION, "Lost connection to backend server.");
do_handle_error(dcb, ERRACT_NEW_CONNECTION, "Lost connection to backend server: network error");
}
return 1;
@ -1381,7 +1400,8 @@ static int gw_backend_hangup(DCB* dcb)
}
else
{
do_handle_error(dcb, ERRACT_NEW_CONNECTION, "Lost connection to backend server.");
do_handle_error(dcb, ERRACT_NEW_CONNECTION,
"Lost connection to backend server: connection closed by peer");
}
return 1;