From 2019d74ad8596f1db6749f545fd0df364ade900b Mon Sep 17 00:00:00 2001 From: richie Date: Sun, 17 May 2026 18:44:05 +0800 Subject: [PATCH] fix: prevent panic on non-MySQL errors in PopulateGroupReplicationInformation The direct type assertion err.(*mysql.MySQLError).Number panics when db.Query returns a non-MySQL error (e.g. network timeout, connection refused, DNS failure, context cancellation). Replace with errors.As() to safely handle all error types including wrapped errors, matching the Go 1.13+ idiom. Fixes a crash in the core instance discovery/monitoring loop that can be triggered by any transient network issue to a Group Replication topology member. --- go/inst/instance_dao.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/go/inst/instance_dao.go b/go/inst/instance_dao.go index 07b3e391..076f74cd 100644 --- a/go/inst/instance_dao.go +++ b/go/inst/instance_dao.go @@ -3468,15 +3468,14 @@ func PopulateGroupReplicationInformation(instance *Instance, db *sql.DB) error { ` rows, err := db.Query(q) if err != nil { - _, grNotSupported := GroupReplicationNotSupportedErrors[err.(*mysql.MySQLError).Number] - if grNotSupported { - return nil // If GR is not supported by the instance, just exit - } else { - // If we got here, the query failed but not because the server does not support group replication. Let's - // log the error - return log.Errorf("There was an error trying to check group replication information for instance "+ - "%+v: %+v", instance.Key, err) + var mysqlErr *mysql.MySQLError + if errors.As(err, &mysqlErr) { + if _, ok := GroupReplicationNotSupportedErrors[mysqlErr.Number]; ok { + return nil // If GR is not supported by the instance, just exit + } } + return log.Errorf("There was an error trying to check group replication information for instance "+ + "%+v: %+v", instance.Key, err) } defer rows.Close() foundGroupPrimary := false