Fix crash in backend command tracking

The backend protocol command tracking didn't check whether the session was
the dummy session. The DCB's session is always set to this value when it
is put into the persistent pool.
This commit is contained in:
Markus Mäkelä
2017-10-08 22:06:43 +03:00
parent 2ca050156f
commit d97742bf66
2 changed files with 27 additions and 13 deletions

View File

@ -199,6 +199,11 @@ MXS_SESSION *session_alloc_with_id(struct service *, struct dcb *, uint64_t);
MXS_SESSION *session_set_dummy(struct dcb *); MXS_SESSION *session_set_dummy(struct dcb *);
static inline bool session_is_dummy(MXS_SESSION* session)
{
return session->state == SESSION_STATE_DUMMY;
}
const char *session_get_remote(const MXS_SESSION *); const char *session_get_remote(const MXS_SESSION *);
const char *session_get_user(const MXS_SESSION *); const char *session_get_user(const MXS_SESSION *);

View File

@ -377,23 +377,32 @@ mxs_auth_state_t handle_server_response(DCB *dcb, GWBUF *buffer)
static inline void prepare_for_write(DCB *dcb, GWBUF *buffer) static inline void prepare_for_write(DCB *dcb, GWBUF *buffer)
{ {
MySQLProtocol *proto = (MySQLProtocol*)dcb->protocol; MySQLProtocol *proto = (MySQLProtocol*)dcb->protocol;
uint64_t capabilities = service_get_capabilities(dcb->session->service);
/** /**
* Copy the current command being executed to this backend. For statement * The DCB's session is set to the dummy session when it is put into the
* based routers, this is tracked by using the current command being executed. * persistent connection pool. If this is not the dummy session, track
* For routers that stream data, the client protocol command tracking data * the current command being executed.
* is used which does not guarantee that the correct command is tracked if
* something queues commands internally.
*/ */
if (rcap_type_required(capabilities, RCAP_TYPE_STMT_INPUT)) if (!session_is_dummy(dcb->session))
{ {
proto->current_command = (mxs_mysql_cmd_t)MYSQL_GET_COMMAND(GWBUF_DATA(buffer)); uint64_t capabilities = service_get_capabilities(dcb->session->service);
}
else if (dcb->session->client_dcb && dcb->session->client_dcb->protocol) /**
{ * Copy the current command being executed to this backend. For statement
MySQLProtocol *client_proto = (MySQLProtocol*)dcb->session->client_dcb->protocol; * based routers, this is tracked by using the current command being executed.
proto->current_command = client_proto->current_command; * For routers that stream data, the client protocol command tracking data
* is used which does not guarantee that the correct command is tracked if
* something queues commands internally.
*/
if (rcap_type_required(capabilities, RCAP_TYPE_STMT_INPUT))
{
proto->current_command = (mxs_mysql_cmd_t)MYSQL_GET_COMMAND(GWBUF_DATA(buffer));
}
else if (dcb->session->client_dcb && dcb->session->client_dcb->protocol)
{
MySQLProtocol *client_proto = (MySQLProtocol*)dcb->session->client_dcb->protocol;
proto->current_command = client_proto->current_command;
}
} }
if (GWBUF_IS_TYPE_SESCMD(buffer)) if (GWBUF_IS_TYPE_SESCMD(buffer))