From 6689c789c95aed8678609031fa7ce2f0c2932131 Mon Sep 17 00:00:00 2001 From: "yuzhong.chen" Date: Mon, 19 Feb 2024 10:24:32 +0800 Subject: [PATCH] fix: show processlist segment fault --- src/protocol/network_server.cpp | 3 ++- src/protocol/show_helper.cpp | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/protocol/network_server.cpp b/src/protocol/network_server.cpp index 3c1ed6ac..fc8f0898 100644 --- a/src/protocol/network_server.cpp +++ b/src/protocol/network_server.cpp @@ -1686,7 +1686,8 @@ void NetworkServer::client_conn_bvars_update() { if (!sock->user_info || !sock->query_ctx) { continue; } - auto command = sock->query_ctx->mysql_cmd; + auto query_ctx = sock->get_query_ctx(); + auto command = query_ctx->mysql_cmd; client_cnt ++; if (command != COM_SLEEP) { running_sql_cnt ++; diff --git a/src/protocol/show_helper.cpp b/src/protocol/show_helper.cpp index 37f3ae94..ee429991 100644 --- a/src/protocol/show_helper.cpp +++ b/src/protocol/show_helper.cpp @@ -1298,16 +1298,18 @@ bool ShowHelper::_show_processlist(const SmartSocket& client, const std::vector< DB_FATAL("param invalid"); return false; } - if (only_show_doing_sql && sock->query_ctx->sql.size() == 0) { + auto query_ctx = sock->get_query_ctx(); + if (only_show_doing_sql && query_ctx->sql.size() == 0) { continue; } DB_WARNING_CLIENT(sock, "processlist, free:%d", sock->is_free); std::vector row; + row.reserve(fields.size()); row.emplace_back(std::to_string(sock->conn_id)); row.emplace_back(sock->user_info->username); row.emplace_back(sock->ip); row.emplace_back(sock->current_db); - auto command = sock->query_ctx->mysql_cmd; + auto command = query_ctx->mysql_cmd; if (command == COM_SLEEP) { row.emplace_back("Sleep"); } else { @@ -1322,7 +1324,7 @@ bool ShowHelper::_show_processlist(const SmartSocket& client, const std::vector< if (command == COM_SLEEP) { row.emplace_back(""); } else { - row.emplace_back(sock->query_ctx->sql); + row.emplace_back(query_ctx->sql); } rows.emplace_back(row); }