From 84b17f9bd8546b3e3e60d990669215115853b709 Mon Sep 17 00:00:00 2001 From: noname0443 Date: Mon, 16 Sep 2024 14:42:57 +0300 Subject: [PATCH] avoid nil pointer dereference panic --- internal/app/app.go | 4 ++-- internal/app/util.go | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/internal/app/app.go b/internal/app/app.go index 02f79fe4..3daf64c6 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -2180,7 +2180,7 @@ func (app *App) getClusterStateFromDB() map[string]*NodeState { getter := func(host string) (*NodeState, error) { return app.getNodeState(host), nil } - clusterState, _ := getNodeStatesInParallel(hosts, getter) + clusterState, _ := getNodeStatesInParallel(hosts, getter, app.logger) return clusterState } @@ -2194,7 +2194,7 @@ func (app *App) getClusterStateFromDcs() (map[string]*NodeState, error) { } return nodeState, nil } - return getNodeStatesInParallel(hosts, getter) + return getNodeStatesInParallel(hosts, getter, app.logger) } func (app *App) waitForCatchUp(node *mysql.Node, gtidset gtids.GTIDSet, timeout time.Duration, sleep time.Duration) (bool, error) { diff --git a/internal/app/util.go b/internal/app/util.go index 1776676b..cdb013c4 100644 --- a/internal/app/util.go +++ b/internal/app/util.go @@ -192,7 +192,7 @@ func getDubiousHAHosts(clusterState map[string]*NodeState) []string { return dubious } -func getNodeStatesInParallel(hosts []string, getter func(string) (*NodeState, error)) (map[string]*NodeState, error) { +func getNodeStatesInParallel(hosts []string, getter func(string) (*NodeState, error), logger *log.Logger) (map[string]*NodeState, error) { type result struct { name string state *NodeState @@ -225,7 +225,12 @@ func getNodeStatesInParallel(hosts []string, getter func(string) (*NodeState, er continue } masterHost := clusterState[host].SlaveState.MasterHost - clusterState[host].MasterState = clusterState[masterHost].MasterState + + if clusterState[masterHost] != nil { + clusterState[host].MasterState = clusterState[masterHost].MasterState + } else { + logger.Error("Can not get master state") + } } return clusterState, nil }