Skip to content

Commit

Permalink
avoid nil pointer dereference panic
Browse files Browse the repository at this point in the history
  • Loading branch information
noname0443 committed Sep 16, 2024
1 parent a0dd73f commit 84b17f9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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) {
Expand Down
9 changes: 7 additions & 2 deletions internal/app/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 84b17f9

Please sign in to comment.