MXS-1921: Explain why session was closed

When a client connection is closed by MaxScale before the client initiates
a controlled closing of the connection, an error message is sent. This
error message now also explains why the connection was closed to make
problem resolution easier.
This commit is contained in:
Markus Mäkelä
2018-06-14 13:48:07 +03:00
parent 315738f279
commit 3d1c2b421a
6 changed files with 67 additions and 1 deletions

View File

@ -2473,6 +2473,7 @@ dcb_accept(DCB *dcb)
{
client_dcb->func.connlimit(client_dcb, client_dcb->service->max_connections);
}
dcb->session->close_reason = SESSION_CLOSE_TOO_MANY_CONNECTIONS;
dcb_close(client_dcb);
client_dcb = NULL;
}
@ -2881,6 +2882,7 @@ void dcb_process_idle_sessions(int thr)
dcb->user ? dcb->user : "<unknown>",
dcb->remote ? dcb->remote : "<unknown>",
(float)idle / 10.f);
dcb->session->close_reason = SESSION_CLOSE_TIMEOUT;
poll_fake_hangup_event(dcb);
}
}

View File

@ -129,6 +129,7 @@ static MXS_SESSION* session_alloc_body(SERVICE* service, DCB* client_dcb,
session->stmt.buffer = NULL;
session->stmt.target = NULL;
session->qualifies_for_pooling = false;
session->close_reason = SESSION_CLOSE_NONE;
MXS_CONFIG *config = config_get_global_options();
// If MaxScale is running in Oracle mode, then autocommit needs to
@ -1211,3 +1212,31 @@ void session_dump_statements(MXS_SESSION* pSession)
}
}
}
const char* session_get_close_reason(const MXS_SESSION* session)
{
switch (session->close_reason)
{
case SESSION_CLOSE_NONE:
return "";
case SESSION_CLOSE_TIMEOUT:
return "Timed out by MaxScale";
case SESSION_CLOSE_HANDLEERROR_FAILED:
return "Router could not recover from connection errors";
case SESSION_CLOSE_ROUTING_FAILED:
return "Router could not route query";
case SESSION_CLOSE_KILLED:
return "Killed by another connection";
case SESSION_CLOSE_TOO_MANY_CONNECTIONS:
return "Too many connections";
default:
ss_dassert(!true);
return "Internal error";
}
}