From 3d21046ffe51d54df30254881a6d2f9e3ba776ce Mon Sep 17 00:00:00 2001 From: Timo Tietavainen Date: Fri, 30 Sep 2022 13:24:59 +0300 Subject: [PATCH] Handle net.SplitHostPort() error Add handling of net.SplitHostPort() function error return value. Issue-Id: RIC-942 Signed-off-by: Timo Tietavainen Change-Id: Ief30f269fe67451144652ba740bb72f3e962799f --- internal/sdlgoredis/sdlgoredis.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/internal/sdlgoredis/sdlgoredis.go b/internal/sdlgoredis/sdlgoredis.go index 7f66f0c..4121bb9 100644 --- a/internal/sdlgoredis/sdlgoredis.go +++ b/internal/sdlgoredis/sdlgoredis.go @@ -850,14 +850,21 @@ func (db *DB) fillDbStateFromDbInfo(info *DbInfo) (*DbState, error) { return &dbState, dbState.Err } -func createReplicaDbClient(host string) *DB { - addr, port, _ := net.SplitHostPort(host) - return createDbClient(addr, port, "", "", "", newRedisClient, subscribeNotifications, nil) +func createReplicaDbClient(host string) (*DB, error) { + addr, port, err := net.SplitHostPort(host) + if err != nil { + return nil, err + } + return createDbClient(addr, port, "", "", "", newRedisClient, subscribeNotifications, nil), err } func getStatisticsInfo(db *DB, host string) (*DbStatisticsInfo, error) { + var err error dbStatisticsInfo := new(DbStatisticsInfo) - dbStatisticsInfo.IPAddr, dbStatisticsInfo.Port, _ = net.SplitHostPort(host) + dbStatisticsInfo.IPAddr, dbStatisticsInfo.Port, err = net.SplitHostPort(host) + if err != nil { + return nil, err + } info, err := db.Info() if err != nil { @@ -884,7 +891,10 @@ func sentinelStatistics(db *DB) (*DbStatistics, error) { if dbState.ReplicasDbState != nil { for _, r := range dbState.ReplicasDbState.States { - replicaDb := createReplicaDbClient(r.GetAddress()) + replicaDb, err := createReplicaDbClient(r.GetAddress()) + if err != nil { + return nil, err + } dbStatisticsInfo, err = getStatisticsInfo(replicaDb, r.GetAddress()) if closeErr := replicaDb.CloseDB(); closeErr != nil { return nil, closeErr -- 2.16.6