From b7d4dfd8520e21dc9bab4c76346c301df99901cd Mon Sep 17 00:00:00 2001 From: JmPotato Date: Tue, 28 Oct 2025 14:54:25 +0800 Subject: [PATCH] fix(resourcecontrol): prevent interface conversion panic in analyze request bypass check (#1777) Signed-off-by: JmPotato --- internal/resourcecontrol/resource_control.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/internal/resourcecontrol/resource_control.go b/internal/resourcecontrol/resource_control.go index dc66c679..27bae2e9 100644 --- a/internal/resourcecontrol/resource_control.go +++ b/internal/resourcecontrol/resource_control.go @@ -63,9 +63,17 @@ func shouldBypass(req *tikvrpc.Request) bool { // Check both coprocessor request type and the request source to ensure the request is an internal analyze request. // Internal analyze request may consume a lot of resources, bypass it to avoid affecting the user experience. // This bypass currently only works with NextGen. - if config.NextGen && (req.BatchCop().GetTp() == reqTypeAnalyze || req.Cop().GetTp() == reqTypeAnalyze) && - strings.Contains(requestSource, util.InternalTxnStats) { - return true + if config.NextGen && strings.Contains(requestSource, util.InternalTxnStats) { + var tp int64 + switch req.Type { + case tikvrpc.CmdBatchCop: + tp = req.BatchCop().GetTp() + case tikvrpc.CmdCop, tikvrpc.CmdCopStream: + tp = req.Cop().GetTp() + } + if tp == reqTypeAnalyze { + return true + } } // Some internal requests should be bypassed, which may affect the user experience. // For example, the `alter user password` request completely bypasses resource control.